"ui";

/* var storage = storages.create("JL2");
 var bbg=storage.get("jiuli");
 if (bbg != 'aut') {
 toast("")
 exit();
 shap(6000000000);
        }
                 var storage = storages.create("JL2");
        storage.put("jiuli", 177433); */

    //通过adb命令自动开启无障碍
    //adb();
    function adb(){
    importClass(android.content.Context);
    importClass(android.provider.Settings);
    try {
        var enabledServices = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        
        var Services = enabledServices + ":com.panic.buy17835357679/com.stardust.autojs.core.accessibility.AccessibilityService";
        Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, Services);
        Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, '1');
        toast("您已成功开启shopping的无障碍服务！");
    } catch (error) {
     /* var storage = storages.create("JL");
 var bbg=storage.get("a");
 if (bbg != 'YnFqcGs1NG82') {
 toast("")
 exit();
            sleep(999999999999);
           
        }
         var storage = storages.create("JL");
         //每次进入界面，先初始化，避免直接访问该界面即可进入。
        storage.put("a", 177433);
       // toast("您未使用自动开无障碍功能！");
        //授权方法：开启usb调试并使用adb工具连接手机，执行 adb shell pm grant org.autojs.autojspro android.permission.WRITE_SECURE_SETTING
        // toast("\n授权代码已复制，请使用adb工具连接手机执行(重启不失效)\n\n", error);
        // setClip("adb shell pm grant com.panic.buy17835357679  android.permission.WRITE_SECURE_SETTINGS");
  */  } 
    }
    
var ColoredButton = (function() {
    //继承ui.Widget
    util.extend(ColoredButton, ui.Widget);

    function ColoredButton() {
        //调用父类构造函数
        ui.Widget.call(this);
        //自定义属性color，定义按钮颜色
        this.defineAttr("color", (view, name, defaultGetter) => {
            return this._color;
        }, (view, name, value, defaultSetter) => {
            this._color = value;
            view.attr("backgroundTint", value);
        });

    }
    ColoredButton.prototype.render = function() {
        return (
            <button textSize="16sp" style="Widget.AppCompat.Button.Colored" w="*" h="auto"/>
        );
    }

    ui.registerWidget("colored-button", ColoredButton);
    return ColoredButton;
})();

var color = "#009688";
ui.statusBarColor("#2F4F4F")
ui.layout(
    <drawer id="drawer" >
        <vertical>
            <appbar>
                <toolbar  id="toolbar"paddingTop="5dp" title=" Shopping assistant v5.96"background="#4C484C" />
                <tabs id="tabs"background="#4C484C" />
            </appbar>
       
            <viewpager id="viewpager">

                //这是多功能界面
                <frame background="#4C484C">  //start
                <ScrollView>
                <vertical> 
                <TextView id="qtv_text" marginLeft="10dp" marginRight="10dp" singleLine="true"  ellipsize="marquee" focusable="true" textColor="red" text="温馨提示：无障碍服务和本软件悬浮窗、后台运行、读取手机内存权限都要开！本助手全自动为您服务，放开双手抢单无忧">
</TextView>
                <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="15sp"/> 
                <Switch id="overlayService" text="悬浮窗权限" checked="{{auto.service != null}}" padding="8 8 8 8"textSize="15sp" />  

                <TextView id="tv_text" marginLeft="10dp" marginRight="10dp" singleLine="true"  ellipsize="marquee" focusable="true" textColor="red" text="温馨提示：点击这里文字一键转bp连接(第三方支持)">
                    </TextView>
                    <colored-button  id="meun"         style="Widget.AppCompat.Button.Colored" text="使用帮助说明"/>
                

<text textSize="14sp"  textColor="RED" text="淘宝："  />
<colored-button  id="ok_bp"           style="Widget.AppCompat.Button.Colored"  text="聚划算BP模式(软件跳转)"/>
<colored-button  id="taobaobp"           style="Widget.AppCompat.Button.Colored"  text="聚划算BP模式(好友界面)"/>
<colored-button  id="ok_bb"           style="Widget.AppCompat.Button.Colored"  text="免密支付BP模式"/>
<colored-button  id="ok_bc"           style="Widget.AppCompat.Button.Colored"  text="定金尾款模式"/>

<colored-button  id="zuobiao"       style="Widget.AppCompat.Button.Colored" text="淘宝首次使用点击获取坐标"/>

<TextView id="pv_text" marginLeft="10dp" marginRight="10dp" singleLine="true"  ellipsize="marquee" focusable="true" textColor="red" text="温馨提示：获取完坐标后，记得取消获取坐标再去淘宝开始运行！否则会崩溃！">
 </TextView>

<colored-button  id="pinduoduo"        style="Widget.AppCompat.Button.Colored" text="拼多多领券"/>




<horizontal>


</horizontal>

                </vertical> 
                </ScrollView>                       
                </frame >  //end

                //这是淘宝界面
                <frame background="#4C484C"> //start
                <ScrollView>
                <vertical>
                <TextView id="ttv_text" marginLeft="10dp" marginRight="10dp" singleLine="true"  ellipsize="marquee" focusable="true" textColor="red" text="温馨提示：软件已默认校准淘宝时间！无障碍服务和本软件悬浮窗、后台运行、读取手机内存权限都要开！本助手全自动为您服务，放开双手抢单无忧">
</TextView>
                
<text textSize="13sp" id="networkTesttwo" textColor="#ff0000" margin="10 5" text="  点击手动校准时间！"/>            
<card w="*" h="80" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="100">
    
    <linear>
    <text textSize="14sp" textColor="black" text="  提前抢购时间"/>
                <input id="delaytime_two" textColor="gray" inputType="number" text="200" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
    </linear>
 <linear>
 <horizontal>
 <text textSize="14sp" textColor="black" text="  提交订单频率"  />
                <input id="interval" textColor="gray" inputType="number" text="100" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                            </horizontal>
 </linear> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>    
            
<card w="*" h="80" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="100">
    
    <linear>
    <text textSize="14sp" textColor="black" text="  抢购重复次数"  />
                <input id="count" textColor="gray" inputType="number" text="3" w="80"/>
                <text textSize="14sp" textColor="black" text="次"  />
    </linear>
 <linear>
 <horizontal>
 <text textSize="14sp" textColor="black" text="  抢购持续时间" />
                <input id="lastTime_two" textColor="gray" inputType="number" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="秒"  />
                            </horizontal>
 </linear> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
              
<card w="*" h="80" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="100">
    
    <linear>
    <text textSize="14sp" textColor="black" text="  商品价格不等于"  />
                <input id="password_7" textColor="gray" inputType="number|numberDecimal" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="元不结算"  />
    </linear>
 <linear>
 <horizontal>
 <text textSize="14sp" textColor="black" text="  提交订单坐标"  />
                <input id="X1" textColor="gray" inputType="number" text="" hint="X轴" w="80"/>
                <input id="X2" textColor="gray" inputType="number" text="" hint="Y轴" w="80"/>
                            </horizontal>
 </linear> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
               
<card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="40">
    
    <linear>
    <linear id="h" layout_gravity="center">                         
                <horizontal>
                <text textSize="14sp" textColor="black" text="  支付密码：" />
                <input id="password_1" textColor="gray"  text="*" w="45"/>
                <input id="password_2" textColor="gray"  text="*" w="45"/>
                <input id="password_3" textColor="gray"  text="*" w="45"/>
                <input id="password_4" textColor="gray"  text="*" w="45"/>
                <input id="password_5" textColor="gray"  text="*" w="45"/>
                <input id="password_6" textColor="gray"  text="*" w="45"/>
                </horizontal>
                </linear>
 </linear> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
<card w="*" h="70" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="60">
    

   
    <text  textSize="12sp" textColor="black" text="  请输入抢购时间,格式为：2021/01/14 12:00:00"/> 
                <input hint="  请在这里输入抢购时间，格式必须正确。" textColor="gray" id="startTime_two" text="  2021/01/14 12:00:00"/> 

</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
                
               
                
      

               
                //定义按钮的大小颜色和文本
                <card w="*" h="30" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="30">
    
<radiogroup orientation="horizontal">
                <checkbox id ="pay1" text=" 自动付款"/>
                <checkbox id ="jiance" text="检测结算价格"/>
                <checkbox id ="bt1" text="隐藏密码" checked="false"/>
                </radiogroup>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>

<card w="*" h="30" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="30">
    
<horizontal>
                <checkbox id ="lianxutijiao" text="连续提交模式"/>
                <checkbox id ="shuaxin" text="提前刷新并勾选"/>
                <checkbox id ="ceshi" text="测试模式"/>
                </horizontal>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
               
                <colored-button  textSize="12sp" id="taobao"  text="使用前必须点我查看说明！坐标获取工具多功能界面➡" style="Widget.AppCompat.Button.Colored"  />
                <colored-button id="ok_two"      layout_gravity="center"  style="Widget.AppCompat.Button.Colored"   text="开始运行"/>
                
                           
                </vertical>
                </ScrollView>
                </frame> //end

                /这是京东界面
                <frame  background="#4C484C"> //start
                <ScrollView>
                <vertical>
                
                <TextView id="itv_text" marginLeft="10dp" marginRight="10dp" singleLine="true"  ellipsize="marquee" focusable="true" textColor="red" text="(京东抢购界面)温馨提示：软件已默认校准京东时间！无障碍服务和本软件悬浮窗、后台运行、读取手机内存权限都要开！本助手全自动为您服务，放开双手抢单无忧">
</TextView>
                <horizontal>
               
                
                </horizontal>
                <text textSize="13sp" id="networkTest_tree" textColor="#ff0000" margin="10 5" text="  点击手动校准京东时间！"/>  
                <card w="*" h="30" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="30">
    

<radiogroup orientation="horizontal">
                <radio id="model_tree" text="页面模式" checked="true"/>
                <radio id="model_four" text="购物车模式" />
                <radio id="model_five" text="BP链接模式" />
                </radiogroup>

</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>

<card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    

<horizontal>
                <text textSize="14sp" textColor="black" text="  提前抢购时间"/>
                <input id="delaytime_tree" textColor="gray" inputType="number" text="800" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>

</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>

<card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    

<horizontal>
                <text textSize="14sp" textColor="black" text="  提交订单频率"  />
                <input id="interval" textColor="gray" inputType="number" text="100" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>

</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>


<card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    
<horizontal>
                <text textSize="14sp" textColor="black" text="  抢购持续时间" />
                <input id="lastTime_tree" textColor="gray" inputType="number" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="秒"  />
                </horizontal>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>

<card w="*" h="70" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
    
<vertical  h="60">
    
<text  textSize="14sp" textColor="black" text="  请输入抢购时间,格式为：2021/01/14 12:00:00"/> 
                <input id="startTime_tree" hint=" 请在这里输入抢购时间，格式必须正确。" textColor="gray"  text="   2021/01/14 12:00:00"/> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
                //定义按钮的大小颜色和文本
                <colored-button  id="jingdong"      textSize="12sp"     style="Widget.AppCompat.Button.Colored"  text="页面模式支持预约抢购和领券商品，使用可以点我查看说明！"/>
                <colored-button id="ok_tree"      layout_gravity="center"       text="开始抢购"/>
               
                <text textSize="14sp" id="networkTest_tree" text=""/>  
                </vertical>
                </ScrollView>
                </frame> //end

                
                <frame background="#4C484C"> //苏宁
                <vertical>
               
                <TextView id="otv_text" marginLeft="10dp" marginRight="10dp" singleLine="true"  ellipsize="marquee" focusable="true" textColor="red" text="(苏宁抢购界面)温馨提示：软件已默认校准苏宁时间！无障碍服务和本软件悬浮窗、后台运行、读取手机内存权限都要开！本助手全自动为您服务，放开双手抢单无忧">
                    </TextView>
                           

                    <text textSize="13sp" id="networkTest" textColor="#ff0000" margin="10 5" text="  点击手动校准苏宁时间！"/>  
                <card w="*" h="40" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="40">
    


<radiogroup orientation="horizontal">
                <radio id="model_one" text="页面模式" checked="true"/>
                <radio id="model_two" text="购物车模式" />
                </radiogroup>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>

<card w="*" h="40" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    

<horizontal>
                <text textSize= "14sp" textColor="black" text="  提前抢购时间"/>
                <input id="delaytime" textColor="gray" inputType="number" text="800" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>

<card w="*" h="40" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    

<horizontal>
                <text textSize="14sp" textColor="black" text="  提交订单频率"  />
                <input id="interval" textColor="gray" inputType="number" text="100" w="80"/>
                <text textSize="14sp" textColor="black" text="毫秒"  />
                </horizontal>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>

<card w="*" h="40" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    

<horizontal>
                <text textSize="14sp" textColor="black" text="  抢购持续时间" />
                <input id="lastTime" textColor="gray" inputType="number" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="秒"  />
                </horizontal>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
//苏灵1234,全部在原来那里加个1
              
<card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="40">
    
    <linear>
    <linear id="h" layout_gravity="center">                         
                <horizontal>
                <text textSize="14sp" textColor="black" text="  支付密码：" />
                <input id="password_11" textColor="gray"  text="继" w="45"/>
                <input id="password_21" textColor="gray"  text="承" w="45"/>
                <input id="password_31" textColor="gray"  text="淘" w="45"/>
                <input id="password_41" textColor="gray"  text="宝" w="45"/>
                <input id="password_51" textColor="gray"  text="密" w="45"/>
                <input id="password_61" textColor="gray"  text="码" w="45"/>
                </horizontal>
                </linear>
 </linear> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
//自动付款
//定义按钮的大小颜色和文本
                <card w="*" h="30" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="30">
    
<radiogroup orientation="horizontal">
                <checkbox id ="pay11" text="SN自动付款"/>
 
                </radiogroup>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>

<card w="*" h="70" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="70">
    

<text  textSize="14sp" textColor="black" text="  请输入抢购时间,格式为:2020/08/27 12:00:00"/> 
                <input hint="  请在这里输入抢购时间，格式必须正确。" textColor="gray" id="startTime" text="2021/01/14 12:00:00"/> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
                //定义按钮的大小颜色和文本
                <colored-button  id="meun"      style="Widget.AppCompat.Button.Colored" text="使用帮助说明"/>
                <colored-button id="ok"      layout_gravity="center"     style="Widget.AppCompat.Button.Colored"   text="开始抢购"/>
              
                <text textSize="14sp" id="networkTest" text=""/>  
                </vertical>
                
                </frame>
            </viewpager>        
        </vertical>
        <vertical layout_gravity="left" bg="#FFFFFF"  w="280">
            <img w="380" h="200" scaleType="fitXY" src="http://pic1.win4000.com/wallpaper/2020-03-12/5e69c8381c24b.jpg"/>
            <list id="menu">
                <horizontal bg="?selectableItemBackground" w="*">
                    <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}"/>
                    <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center"/>
                </horizontal>
            </list>
        </vertical>
    </drawer>
);

//=================================================================================1234
function clicktext(ui) {
    if (text(ui).exists()) {
        var a = text(ui).findOnce();
var hhhh=random(-10,10)
        if (a) {
            var b = a.bounds();
            var timeq=random(50,150)
            if (b) {
                press(b.centerX()+hhhh, b.centerY()+hhhh,timeq);
                sleep(random(30,50))
            
            }
        }

    }
}
function clicktextContains(ui) {
    if (textContains(ui).exists()) {
        var a = textContains(ui).findOnce();
var hhhh=random(-5,5)
        if (a) {
            var b = a.bounds();
            var timeq=random(50,100)
            if (b) {
                press(b.centerX()+hhhh, b.centerY()+hhhh,timeq);
                sleep(random(1,10))
            
            }
        }

    }
}
var 连续提交 = "无"
var xxx=device.width/2;
var yyy=device.height*0.962;

ui.qtv_text.setSelected(true);
ui.otv_text.setSelected(true);
ui.itv_text.setSelected(true);
ui.tv_text.setSelected(true);
ui.ttv_text.setSelected(true);
ui.pv_text.setSelected(true);
ui.lianxutijiao.on("check", (checked)=>{
    if(checked){
        连续提交= "有"
        toast("已开启连续提交功能，此功能必须填写坐标！");
    }
    else
    {
        连续提交 = "无"
    }
});
ui.tv_text.setSelected(true);
ui.zuobiao.click(function () {
    if(ui.zuobiao.getText()=="点击获取坐标") {
        ui.zuobiao.setText("取消获取坐标");    
        threads.start(获取坐标);
        device.keepScreenOn()//保持屏幕常亮
    }else{
        ui.zuobiao.setText("点击获取坐标");
        console.clear();
        console.hide();
        threads.shutDownAll();
        device.cancelKeepingAwake();   
        }
})

ui.taobao.on("click",function(){
    //app.openUrl("http://www.lingjuan.cc/post-114.html/")
    app.openUrl("https://shimo.im/docs/Jv9DVrxyTyPXxrJw/")
})
ui.jingdong.on("click",function(){
    //app.openUrl("http://www.lingjuan.cc/post-115.html/")
    app.openUrl("https://shimo.im/docs/Jv9DVrxyTyPXxrJw/")
})
ui.tv_text.on("click",function(){
    //app.openUrl("http://www.lingjuan.cc/post-114.html/")
    app.openUrl("http://www.cqypp.cn:808/")
})
var 开启刷新 = "无"
var 提前刷新 = "无"
ui.shuaxin.on("check", (checked)=>{
    if(checked){
        开启刷新= "有"
        提前刷新 = "有"
        toast("已开启购物车自动刷新功能！");
    }
    else
    {
        开启刷新 = "无"
        提前刷新 = "无"
    }
});
var 自动付款 = "无"
ui.pay1.on("check", (checked)=>{
    if(checked){
        自动付款= "有"
        toast("已开启自动付款");
    }
    else
    {
        自动付款 = "无"
    }
});
ui.pay11.on("check", (checked)=>{
    if(checked){
        自动付款1= "有"
        toast("已开启SN自动付款");
    }
    else
    {
        自动付款1 = "无"
    }
});

var 自动勾选 = "无"
var 手动勾选 = "有"
ui.jiance.on("check", (checked)=>{
    if(checked){
        自动勾选= "有"
        toast("已开启自动勾选商品，并检测价格进行结算！"); 
        手动勾选 = "无" 
    }
    else
    {
        自动勾选 = "无"
    }
});
//淘宝密码隐藏
ui.bt1.on("check", (checked)=>{
    if (ui.bt1.getText() == "隐藏密码") {
        ui.bt1.setText("显示密码");
        ui.h.visibility = 8;
        toast("密码已隐藏!");
    } else {
        ui.bt1.setText("隐藏密码");
        ui.h.visibility = 0;
        toast("密码已显示!");
    }
});


var 平台类别2="苏宁页面"
ui.model_one.on("check", (checked)=>{
    if(checked){
        平台类别2="苏宁页面" 
        toast("已切换到苏宁页面抢购模式")
    }
});
ui.model_two.on("check", (checked)=>{
    if(checked){
        平台类别2="苏宁购物车" 
        toast("已切换到苏宁购物车抢购模式")    
    }
});

var 平台类别="京东页面"
ui.model_tree.on("check", (checked)=>{
    if(checked){
        平台类别="京东页面" 
        toast("已切换到京东页面抢购模式")
    }
});
ui.model_four.on("check", (checked)=>{
    if(checked){
        平台类别="京东购物车" 
        toast("已切换到京东购物车抢购模式")    
    }
});
ui.model_five.on("check", (checked)=>{
    if(checked){
        平台类别="京东BP链接" 
        toast("已切换到京东BP链接抢购模式")    
    }
});

var 测试 = "无"
ui.ceshi.on("check", (checked)=>{
    if(checked){
      测试 = "有"    
    }
    else
    {
       测试 = "无"
    }
});
    //创建选项菜单(右上角)
    ui.emitter.on("create_options_menu", menu=>{ 
        menu.add("日志");  
        menu.add("设置");
        menu.add("关于");
    });
    //监听选项菜单点击
    ui.emitter.on("options_item_selected", (e, item)=>{
        switch(item.getTitle()){
            case "设置":
                app.startActivity(Settings)
                break;
              
            case "关于":
                alert("关于", "当前版本号:"+"Shopping v5.96");
                break;
            case "日志":
                //app.startActivity("console");
                toast("在本地根目录")
                break;
    }
            e.consumed = true;
    });
    activity.setSupportActionBar(ui.toolbar);
    ui.meun.on("click", () => {
        var 使用帮助说明 = "https://shimo.im/docs/Jv9DVrxyTyPXxrJw/"
        toast("打开");
        app.openUrl( 使用帮助说明);
    });
    //设置滑动页面的标题
    ui.viewpager.setTitles(["supermk","TB","JD","SN"]);
    //让滑动页面和标签栏联动
    ui.tabs.setupWithViewPager(ui.viewpager);
    //让工具栏左上角可以打开侧拉菜单
    ui.toolbar.setupWithDrawer(ui.drawer);

    ui.menu.setDataSource([
    {
         title: "QQ交流群",
            icon: "@drawable/ic_home_black_48dp"
    },
    {
         title: "使用说明",
            icon: "@drawable/ic_description_black_48dp"
    },
    {
         title: "联系作者",
            icon: "@drawable/ic_face_black_48dp"
    },
  
     {
         title: "检查更新",
            icon: "@drawable/ic_settings_black_48dp"
     },
    {
         title: "退出",
         icon: "@drawable/ic_exit_to_app_black_48dp"
    },
]);

    ui.menu.on("item_click", item =>{
        switch(item.title){
            case"QQ交流群":
           toastLog("暂无")
                break;
    }
    });
    ui.menu.on("item_click", item =>{
        switch(item.title){
            case"使用说明":
            app.openUrl("https://shimo.im/docs/Jv9DVrxyTyPXxrJw/");
    }
    });
    ui.menu.on("item_click", item =>{
         switch(item.title){
            case"联系作者":
            toastLog("请自行联系")
     }
    });

    ui.menu.on("item_click", item =>{
        switch(item.title){
            case"检查更新":         
                const versionName = "shopping v5.96";
                //const baseUrl = "http://abc.svip925.top/";
                toast("进群获得最新消息");
                //var res = http.get(baseUrl + "codelist.php?user=2818908400").body.json();
                var a = [];
                try {
                var name = res[0].fileName;
                var a = name.slice(name.indexOf("v") + 1, name.indexOf(".j"));
                var ver = versionName.slice(versionName.indexOf("v"), versionName.length).replace(/\D/g, '');
                if (ver < a.replace(/\D/g, '')) {
                    confirm("发现最新版本", "当前版本：" + versionName + "\n\n最新版本：shopping v" + a, (value) => {
                        if (value) {
                 threads.start(function() {
                    toast("正在更新…");
                  codePath = engines.myEngine().cwd() + "/main.js";
                 //files.write(codePath, http.get(baseUrl + "download.php?user=2818908400&name=" + name).body.string())
                 toast("更新完成\n\n正在打开…");
                 engines.execScriptFile(codePath);
                 toast("版本已更新为:shopping v"+a)
                  exit();
                })
                }
                else {
                    toast("已取消更新，下次打开将再次提示！")
                } 
                })
            }
            else {
                toast("版本检查完成：暂无新版本");
            };
                } catch (e) {
                    
                }          
    }
    });
    ui.menu.on("item_click", item => {
        switch(item.title){
            case "退出":
            ui.finish();
            break;
    }
    });

 
    //这里是无障碍触发方式
    ui.autoService.on("check", function(checked) {
    // 用户勾选无障碍服务的选项时，跳转到页面让用户去开启 
    if(checked && auto.service == null) { 
     app.startActivity({
     action: "android.settings.ACCESSIBILITY_SETTINGS"  }); } 
      if(!checked && auto.service != null){ 
     auto.service.disableSelf();    }    }); 
   // 当用户回到本界面时，resume事件会被触发
     ui.emitter.on("resume", function() {
    // 此时根据无障碍服务的开启情况，同步开关的状态 
    ui.autoService.checked = auto.service != null;    }); 
   //开启悬浮窗权限
    ui.overlayService.on("check", function (checked) {
    // 用户勾选无障碍服务的选项时，跳转到页面让用户去开启
    if (checked) {
        int = app.startActivity({
            packageName: "com.android.settings",
            className: "com.android.settings.Settings$AppDrawOverlaySettingsActivity",
            data: "package:" + auto.service.getPackageName().toString()
        });
        toast("请打开悬浮窗开关");
    }

     if (!checked && auto.service != null) {
         auto.service.disableSelf();
         toast("已关闭悬浮窗权限");
         }
    });


    ui.ok_bb.on("click", () => {

        engines.execScriptFile("tb_bp.js");

    });
    //定金尾款
    //bp模式
    
        ui.ok_bc.on("click", () => {

        engines.execScriptFile("tb_bb.js");

    });
    
    ui.taobaobp.on("click", () => {

        engines.execScriptFile("taobaobp.js");

    });
    
    ui.ok_bp.on("click", () => {
        // engines.execScriptFile("tb_bp.js");
        "ui";

var color = "#009688";
ui.statusBarColor("#2F4F4F")
ui.layout(
    <drawer id="drawer" >
        <vertical>
            <appbar>
                <toolbar  id="toolbar"paddingTop="5dp" title="聚划算百亿补贴模式" background="#4C484C" />
            </appbar>
       
            <viewpager id="viewpager">
                //这是聚划算界面
                <frame background="#4C484C"> //start
                <ScrollView>
                <vertical>
                <TextView id="wtv_text" marginLeft="10dp" marginRight="10dp" singleLine="true"  ellipsize="marquee" focusable="true" textColor="red" text="温馨提示：软件已默认校准淘宝时间！无障碍服务和本软件悬浮窗、后台运行、读取手机内存权限都要开！本助手全自动为您服务，放开双手抢单无忧">
                    </TextView>
                <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="13sp"/>
                {/* <Switch id="overlayService" text="悬浮窗权限" checked="{{auto.service != null}}" padding="8 8 8 8"textSize="13sp" />
                  */}
               
               //定义按钮的大小颜色和文本
                <colored-button id="lianjie" text="请输入商品BP链接！支持百亿补贴！如何获取请点击我！⬅" textSize="12sp" />
                <colored-button  id="ok_two"      layout_gravity="center"  style="Widget.AppCompat.Button.Colored"     text="开始运行"/>
                <colored-button  id="fastTbUrlOpen"       layout_gravity="center"    style="Widget.AppCompat.Button.Colored"   text="点击跳转"/>
                <card w="*" h="40" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="40">
    

<radiogroup orientation="horizontal">
                <checkbox id ="pay1" text="自动付款"/>
                <checkbox id ="tijiao" text="检测提交价格"/>
                <checkbox id ="bt1" text="隐藏密码" checked="false"/>
                </radiogroup> 

</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
               
<card w="*" h="100" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="90">
    

<text textSize="14sp" textColor="black" text="  商品BP链接:" />
                <input id="id1" textColor="gray"  text=" h5.m.taobao.com/cart/order.html?  buyParam=610051376150_1_0" w="*"/>

</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>               

<card w="*" h="80" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="100">
    
    <linear>
    <text textSize="13sp" textColor="black" text="  提前抢购时间"/>
                <input id="delaytime_two" textColor="gray" inputType="number" text="700" w="80"/>
                <text textSize="13sp" textColor="black" text="毫秒"  />
    </linear>
 <linear>
 <horizontal>
 <text textSize="13sp" textColor="black" text="  提交订单频率"  />
                <input id="interval" textColor="gray" inputType="number" text="100" w="80"/>
                <text textSize="13sp" textColor="black" text="毫秒"  />
                            </horizontal>
 </linear> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>           

<card w="*" h="80" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="100">
    
    <linear>
    <text textSize="13sp" textColor="black" text="  抢购持续时间" />
                <input id="lastTime_two" textColor="gray" inputType="number" text="10" w="80"/>
                <text textSize="13sp" textColor="black" text="秒"  />
    </linear>
 <linear>
 <horizontal>
 <text textSize="14sp" textColor="black" text="  商品价格不等于"  />
                <input id="password_7" textColor="gray" inputType="number|numberDecimal" text="10" w="80"/>
                <text textSize="14sp" textColor="black" text="元不提交"  />
                            </horizontal>
 </linear> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>         

<card w="*" h="40" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="40">
    
<linear id="h" layout_gravity="center">                         
                <horizontal>
                <text textSize="13sp" textColor="black" text="  支付密码：" />
                <input id="password_1" textColor="gray"  text="*" w="45"/>
                <input id="password_2" textColor="gray"  text="*" w="45"/>
                <input id="password_3" textColor="gray"  text="*" w="45"/>
                <input id="password_4" textColor="gray"  text="*" w="45"/>
                <input id="password_5" textColor="gray"  text="*" w="45"/>
                <input id="password_6" textColor="gray"  text="*" w="45"/>
                </horizontal>
                </linear>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>             
<card w="*" h="70" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="70">
    
<text  textSize="13sp" textColor="black" text="请输入抢购时间,格式为：2021/01/14 12:00:00"/> 
                <input hint="请在这里输入抢购时间，格式必须正确。" textColor="gray" id="startTime_two" /> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
              
                
                <text textSize="13sp" id="networkTesttwo" textColor="RED" margin="0 5" text="点此手动校准时间"/>
                </vertical>
                </ScrollView>
                </frame> //end

            </viewpager>        
        </vertical>
    </drawer>
);
function clickUiBounds(ui) {
    if (ui.exists()) {
        var a = ui.findOnce();
        if (a) {
            var b = a.bounds();
            if (b) {
                click(b.centerX(), b.centerY());
                return true;
            }
        }

    }
    return false;
}

ui.wtv_text.setSelected(true);
ui.lianjie.on("click",function(){
    app.openUrl("https://shimo.im/docs/hcPDXJhHPwdYPryd/")
})
//bp跳转
ui.fastTbUrlOpen.on("click", () => {
    if(ui.id1.text() ==""){
        toast("请输入商品的BP链接！")
    }
    else {
    var url = ui.id1.text();
    app.startActivity({
        action: "android.intent.action.VIEW",
        data: "taobao://" + url,
        packageName: "com.taobao.taobao",
    });
    }
});
var 不提交订单 = "无"
var 提交订单 = "有"
ui.tijiao.on("check", (checked)=>{
    if(checked){
        不提交订单 = "有"
        提交订单 = "无"
        toast("检测商品提交价格，大于预定价格不提交！"); 
    }
    else
    {
        不提交订单 = "无"
        提交订单 = "有"
    }
});
//密码隐藏
ui.bt1.on("check", (checked)=>{
    if (ui.bt1.getText() == "隐藏密码") {
        ui.bt1.setText("显示密码");
        ui.h.visibility = 8;
        toast("密码已隐藏!");
    } else {
        ui.bt1.setText("隐藏密码");
        ui.h.visibility = 0;
        toast("密码已显示!");
    }
});
//自动付款
var 自动付款 = "无"
ui.pay1.on("check", (checked)=>{
    if(checked){
        自动付款= "有"
        toast("已开启自动付款"); 
    }
    else
    {
        自动付款 = "无"
    }
});


 //这里是无障碍触发方式
 ui.autoService.on("check", function(checked) {
    // 用户勾选无障碍服务的选项时，跳转到页面让用户去开启 
    if(checked && auto.service == null) { 
     app.startActivity({
     action: "android.settings.ACCESSIBILITY_SETTINGS"  }); } 
      if(!checked && auto.service != null){ 
     auto.service.disableSelf();    }    }); 
   // 当用户回到本界面时，resume事件会被触发
     ui.emitter.on("resume", function() {
    // 此时根据无障碍服务的开启情况，同步开关的状态 
    ui.autoService.checked = auto.service != null;    }); 
//    //开启悬浮窗权限
//     ui.overlayService.on("check", function (checked) {
//     // 用户勾选无障碍服务的选项时，跳转到页面让用户去开启
//     if (checked) {
//         int = app.startActivity({
//             packageName: "com.android.settings",
//             className: "com.android.settings.Settings$AppDrawOverlaySettingsActivity",
//             data: "package:" + auto.service.getPackageName().toString()
//         });
//         toast("请打开悬浮窗开关");
//     }

//      if (!checked && auto.service != null) {
//          auto.service.disableSelf();
//          toast("已关闭悬浮窗权限");
//          }
//     });
/**
 *  不能点击的控件，通过坐标点击
 * @param {*} uiSelector
 */


    // 获取时分秒用于记录日志
    function logWithTime(msg) {
        console.info(formatDate(getNow()) + " " + msg);
       }
   
       // 检测淘宝网络延迟和时间偏差
       var NTP = {
       requiredResponses: 3,
       serverTimes: [],//服务器时间
       serverDelay: [],//服务器延迟
       serverUrl: "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp",
       resyncTime: 0, // minutes
       sync: function () {
           var offset = storage.get("NTPClockOffset");//获取时钟偏移
           if (offset) {
               try {
                   var t = offset.split("|")[1];
                   var d = NTP.fixTime() - parseInt(t, 10);
                   if (d < (1000 * 60 * NTP.resyncTime)) {
                       return false;
                   }
               } catch (e) {
               }
           }
           NTP.getServerTime();
       },
       getNow: function () {
           var date = new Date();
           return date.getTime();
       },
       //分析服务器响应
       parseServerResponse: function (data) {
           var NtpStartTime = storage.get("NtpStartTime");
           var NtpStopTime = NTP.getNow();
           var origtime = parseInt(data.data.t);//起始时间
           var delay = ((NtpStopTime - NtpStartTime) / 2);//延迟
           var offset = NtpStopTime - origtime - delay;//抵消
           NTP.serverTimes.push(offset);
           NTP.serverDelay.push(delay);
   
           // 因为网络问题，需要多次获取偏移值，获取平均值
           if (NTP.serverTimes.length >= NTP.requiredResponses) {
               var sumOffset = 0;
               var sumDelay = 0;
               var i = 0;
               for (i = 0; i < NTP.serverTimes.length; i++) {
                   sumOffset += NTP.serverTimes[i];
                   sumDelay += NTP.serverDelay[i];
               }
               var averageOffset = Math.round(sumOffset / i);
               var averageDelay = Math.round(sumDelay / i);
               storage.put("NTPClockOffset", averageOffset + '|' + NTP.fixTime()); // 保存获得offset时的时间戳
               storage.put("NTPClockDelay", averageDelay); // 保存获得offset时的时间戳
           } else {
               NTP.getServerTime();
           }
       },
       //获取服务器时间并判断是否获取成功
       getServerTime: function () {
           var NtpStartTime = NTP.getNow();
           storage.put("NtpStartTime", NtpStartTime);
           var res = http.get(NTP.serverUrl);
           if (res.statusCode !== 200) {
               toast("获取网络时间失败: " + res.statusCode + " " + res.statusMessage);
               return false;
           } else {
               NTP.parseServerResponse(res.body.json());
           }
       },
       //固定时间
       fixTime: function (timeStamp) {
           if (!timeStamp) {
               timeStamp = NTP.getNow();
           }
           var offset = storage.get("NTPClockOffset");
           try {
               if (!offset) {
                   offset = 0;
               } else {
                   offset = offset.split("|")[0];
               }
               if (isNaN(parseInt(offset, 10))) {
                   return timeStamp;
               }
               return timeStamp + parseInt(offset, 10);
           } catch (e) {
               return timeStamp;
           }
       }
   };
   
   
   
   
       // 获取默认开始时间
       function getTime() {
           var fmt = "YYYY-MM-dd hh:mm:ss";
           var d = new Date();
           var hh = d.getHours();
           var mm = d.getMinutes();
           var ss = d.getSeconds();
           if (mm < 30) {
            mm = 30
            ss = 00
           }
           else{
            hh+=1
            mm = 00
            ss = 00       
           }
           
           var o = {
               "Y+": d.getYear() + 1900,
               "M+": d.getMonth() + 1,
               "d+": d.getDate(),
               "h+": hh,
               // "m+": d.getMinutes(),
               // "s+": d.getSeconds()
               "m+": mm,
               "s+": ss
           };
           for (var k in o) {
               if (new RegExp("(" + k + ")").test(fmt)) {
                   fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 4) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
               }
           }
           fmt = fmt.replace(/-/g, '/');
           return fmt;
         };
   
         //定义初始化界面数据
         var storage = storages.create("tmalltaobaohelper.byfly");
         threads.start(NTP.sync);
   
         //初始化淘宝界面
       setTimeout(initConfig_two, 500);
       function initConfig_two() {
           NTPClockOffset = storage.get("NTPClockOffset", "0");
           NTPClockDelay = storage.get("NTPClockDelay", "0");
       if (!NTPClockOffset) {
           NTPClockOffset = 0;
       } else {
           NTPClockOffset = parseInt(NTPClockOffset.split("|")[0]);
       }
       if (NTPClockOffset < 0) {
           var offset_str = "慢了" + -NTPClockOffset + 'ms，'
       } else {
           offset_str = "快了" + NTPClockOffset + 'ms，'
       }
       if (NTPClockDelay < 50) {
           var good_str = "网速评估:"+"您的网络延迟低于50ms,优秀啊老铁！" 
       } 
       else if (NTPClockDelay < 100) {
           var good_str = "网速评估:"+"您的网络延迟低于100ms,还可以！" 
       } 
       else if (NTPClockDelay>100 && NTPClockDelay<200) {
           var good_str = "网速评估:"+"您的网络延迟高于100ms,抢购可能会有影响！" 
       } 
       else {
           good_str = "网速评估:"+"您的网络不适合抢购，建议切换网络！" 
       }
   
       ui.networkTesttwo.on("click",function(){
           ui.networkTesttwo.setText("时间校准:"+"本地时间比淘宝" + offset_str +"已经为您校准了淘宝时间！"+'\n'+ "网络延迟：" + NTPClockDelay+'\n'+good_str );
           });       
   
           ui.startTime_two.setText(getTime());
           ui.interval.setText(storage.get("interval", "100").toString());
           ui.lastTime_two.setText(storage.get("lastTime_two", "10").toString());   
           ui.delaytime_two.setText(storage.get("delaytime_two", "700").toString());  
         }

              // 时间戳转时间字符串
    function add0(m) {
        return m < 10 ? '0' + m : m
    }
    function getNow() {
        var now = new Date().getTime();
        return now - NTPClockOffset; 
    }

    function formatDate(needTime) {
        //needTime是整数，否则要parseInt转换
        var time = new Date(parseInt(needTime));
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        var S = time.getMilliseconds();
        return add0(h) + ':' + add0(mm) + ':' + add0(s)+":"+add0(S);
    }


      // 检测时间字符串是否有效
    function strDateTime(str) {
        var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
        var r = str.match(reg);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
        return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
    }

    var storage3 = storages.create("这个是一个文件名2");
    for (i = 0; i < 7; i++) {
    var content2 = storage3.get("password_" + (i + 1));
    
    if (content2) {
        ui["password_" + (i + 1)].setText(content2);
    }}

    var storage4 = storages.create("这个是一个文件");
    for (i = 0; i < 1; i++) {
    var content4 = storage4.get("id" + (i + 1));
    
    if (content4) {
        ui["id" + (i + 1)].setText(content4);
    }
    }

      // 淘宝程序主要逻辑123456
      ui.ok_two.click(function () {
        // 检查无障碍服务
        if (auto.service == null) {
               toast("请先开启无障碍服务！");
               return;
           }
           
           arr = new Array();
           for (i = 0; i < 7; i++) {
           var content2 = ui["password_" + (i + 1)].getText() + "";
           storage3.put("password_" + (i + 1), content2);
           arr.push(content2);
           };


           arr2 = new Array();
           for (i = 0; i < 1; i++) {
           var content4 = ui["id" + (i + 1)].getText() + "";
           storage4.put("id" + (i + 1), content4);
           arr2.push(content4);
           };

   
       //接收界面数据
           startTime_two = ui.startTime_two.getText().toString();
           interval = parseInt(ui.interval.getText());
           lastTime_two = parseInt(ui.lastTime_two.getText());
           delaytime_two = parseInt(ui.delaytime_two.getText());
           if (!strDateTime(startTime_two)) {
               ui.startTime_two.setError("日期错误，请重新输入！");
               return;
           }
           //传递界面数据      
           storage.put("interval", interval);
           storage.put("lastTime_two", lastTime_two);
           storage.put("delaytime_two", delaytime_two);
   
           //按下开始运行
             if(ui.ok_two.getText()=="开始运行") {
               ui.ok_two.setText("停止运行");    
               threads.start(main_two);
               device.keepScreenOn()//保持屏幕常亮
           }else{
               ui.ok_two.setText("开始运行");
               console.clear();
               console.hide();
               threads.shutDownAll();
               device.cancelKeepingAwake();   
               }
       
   });
 //这是淘宝主程序 123456789
 function main_two() {
    var middle = device.width / 2 -400;      
    console.setPosition(middle, 0);
    console.setGlobalLogConfig({ "file": "/sdcard/shopping日志.txt" });
    console.show();
    var DetailPage =0;
    var notDetailPage = 0;
    var notInDetailPage = 0

    logWithTime("欢迎使用shopping淘宝BP链接模式!"); 
    sleep(800); 
    logWithTime("请勿用于非法用途");  
    sleep(800); 
    logWithTime("请打开手机淘宝，并重新切换到点击跳转页面！");
    sleep(800); 
    var startTime2 = new Date(Date.parse(startTime_two)).getTime();
    var endTime = new Date(startTime2.valueOf() + lastTime_two * 1000).getTime();
    var shoppingingtime = startTime2 - delaytime_two;

    reviewtime();
     //判断实际时间是否大于抢购时间
function reviewtime(){
    var tt = getNow();
       if (tt > shoppingingtime) {
            console.warn("您的时间已经错过了哦,请重新输入时间！");
            sleep(2000);
            console.clear();
            console.hide();
            threads.shutDownAll();
        }
       if (tt < shoppingingtime){
            logWithTime("您的抢购时间为：" + formatDate(shoppingingtime));
            logWithTime("距离抢购时间还剩"+(startTime2-tt)/1000+"秒"+"请耐心等待");
            }
        }
         // 检测是否在商品详情页
x = setInterval(function () {
    var t = getNow();
    if (t < shoppingingtime) {
        if (className("android.widget.Button").text("点击跳转").exists()) {
            if (DetailPage === 0) {
                logWithTime("已找到跳转按钮，请等待......");
                DetailPage++;
                notDetailPage = 0
            }

        } else {
            if (notInDetailPage === 0) {
                logWithTime("未找到跳转按钮，否则无法进行跳转！");
                DetailPage = 0;
                notInDetailPage++
            }
        }
    } else {
        not_in_Detail_Page = 0;  // 商品详情页状态复位
        clearInterval(x)
    }
}, 500);

z = setInterval(function () {
    var t = getNow();
    if(t >= shoppingingtime && t < endTime){                
        logWithTime("开始抢购")
        BP链接();
        clearInterval(z);        
    }  
  },10)      
};
function BP链接()
{
    var 价格值 = ui.password_7.text()
    var 跳转 = "有"
    var Crowding = 0;
    var cishu = 0;
    var endTime = lastTime_two * 1000;
    var password_1 = ui.password_1.text()*1;    
    var password_2 = ui.password_2.text()*1;
    var password_3 = ui.password_3.text()*1;
    var password_4 = ui.password_4.text()*1;
    var password_5 = ui.password_5.text()*1;
    var password_6 = ui.password_6.text()*1;
            //如果在购物车
        threads.start(function(){
            setInterval(function(){
                if(跳转 == "有"){
            if (className("android.widget.Button").text("点击跳转").exists()) {
                logWithTime("准备跳转");
                className("android.widget.Button").text("点击跳转").findOne().click()
                logWithTime("已跳转");
                跳转 = "无"
                }}
            },100)
        })
        threads.start(function(){
            setInterval(function(){ 
        if (className("android.widget.TextView").text("加入购物车").exists()) {
            var 领卷购买=id("com.taobao.taobao:id/detail_main_sys_button").findOne()
            press(领卷购买.bounds().centerX()+344,领卷购买.bounds().centerY(),1)
            id("confirm").findOne().click()
            }
        }, 100);
        });

        threads.start(function(){
            setInterval(function(){ 
        if (id("confirm").exists()) {
            id("confirm").findOne().click()
        }
        }, 100);
        });    

        if(不提交订单 == "有"){
            var 校验价格 = "真"
            if(校验价格 == "真"){
                threads.start(function(){
                    setInterval(function(){  
                    if(className("android.widget.TextView").text("￥"+价格值).depth(12).exists()&&className("android.widget.TextView").text("提交订单").exists())
                    {
                        logWithTime("已找到符合预定价格的商品，开始提交订单！");
                        className("android.widget.TextView").text("提交订单").findOne().click();
                        找到了 = "真"
                    }   
                    else if(className("android.widget.TextView").text("提交订单").exists())
                    {
                        logWithTime("没有找到符合预定价格的商品，不提交订单！");
                        Panic_buying_end()
                    }                 
            },200)
            })
            }
            }
   

        if(提交订单 == "有"){
        threads.start(function(){
            setInterval(function(){
            if (className("android.widget.TextView").text("提交订单").exists()) {
                    logWithTime("正在尝试提交订单");
                    className("android.widget.TextView").text("提交订单").findOne().click();
                    logWithTime("订单已提交");             
                    }
                },10)
            })}
        threads.start(function(){
            setInterval(function(){
            if (className("android.widget.TextView").textContains("加载中").exists()) {
                    if (Crowding === 0){
                        Crowding = 1
                        logWithTime("页面加载中");
                        }          
                    }
                },10)
            })
            threads.start(function(){
                setInterval(function(){
            if (className("android.widget.TextView").text("我知道了").exists()) {
                        className("android.widget.TextView").text("我知道了").findOne().click();
                        found = true;
                        cishu++;
                        logWithTime("第" + cishu + "次拥挤了，再试一次吧！");             
                    }
                },10)
            })
        threads.start(function(){
            setInterval(function(){
            if (className("android.widget.TextView").text("立即付款").exists()) {
                if(自动付款 == "无"){
                        logWithTime("抢购成功！请支付！");
                        device.cancelKeepingAwake(); 
                        Panic_buying_end()             
                    }}
                    if(自动付款 == "有")
                    {
                        click("立即付款")                            
                    } 
                },200)
            })  
            var 密码1 = "真"
            var 密码2 = "假"
            var 密码3 = "假"
            var 密码4 = "假"
            var 密码5 = "假"
            var 密码6 = "假"
            threads.start(function(){
                setInterval(function(){ 
                if (className("android.widget.TextView").text("请输入支付密码").exists()) { 
                    if(密码1 == "真"&&className("android.widget.TextView").text(password_1).exists()){click(password_1);密码2 = "真";sleep(10)}
                    if(密码2 == "真"&&className("android.widget.TextView").text(password_2).exists()){click(password_2);密码3 = "真";sleep(10)}
                    if(密码3 == "真"&&className("android.widget.TextView").text(password_3).exists()){click(password_3);密码4 = "真";sleep(10)}
                    if(密码4 == "真"&&className("android.widget.TextView").text(password_4).exists()){click(password_4);密码5 = "真";sleep(10)}
                    if(密码5 == "真"&&className("android.widget.TextView").text(password_5).exists()){click(password_5);密码6 = "真";sleep(10)}
                    if(密码6 == "真"&&className("android.widget.TextView").text(password_6).exists()){click(password_6);Panic_buying_end()}
                } 
            },300)
            })
        threads.start(function(){
            setInterval(function(){ 
            if (className("android.view.View").desc("查看订单").findOne().parent().exists()) { 
                logWithTime("支付成功！");
                Panic_buying_end()
            }
        },10)
        })  
        threads.start(function(){
            setInterval(function(){ 
                sleep(endTime)
                logWithTime("超出预定抢购时长，抢购结束");
                device.cancelKeepingAwake();
                Panic_buying_end();           
            
        },10)
    })  
}



function Panic_buying_end(){    
device.cancelKeepingAwake()//关闭屏幕常亮
logWithTime("本次抢购结束");
threads.shutDownAll()
}

    });
    // 获取时分秒用于记录日志
    function logWithTime(msg) {
     console.info(formatDate(getNow()) + " " + msg);
    }

    // 检测淘宝网络延迟和时间偏差
    var NTP = {
    requiredResponses: 3,
    serverTimes: [],//服务器时间
    serverDelay: [],//服务器延迟
    serverUrl: "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp",
    resyncTime: 0, // minutes
    sync: function () {
        var offset = storage.get("NTPClockOffset");//获取时钟偏移
        if (offset) {
            try {
                var t = offset.split("|")[1];
                var d = NTP.fixTime() - parseInt(t, 10);
                if (d < (1000 * 60 * NTP.resyncTime)) {
                    return false;
                }
            } catch (e) {
            }
        }
        NTP.getServerTime();
    },
    getNow: function () {
        var date = new Date();
        return date.getTime();
    },
    //分析服务器响应
    parseServerResponse: function (data) {
        var NtpStartTime = storage.get("NtpStartTime");
        var NtpStopTime = NTP.getNow();
        var origtime = parseInt(data.data.t);//起始时间
        var delay = ((NtpStopTime - NtpStartTime) / 2);//延迟
        var offset = NtpStopTime - origtime - delay;//抵消
        NTP.serverTimes.push(offset);
        NTP.serverDelay.push(delay);

        // 因为网络问题，需要多次获取偏移值，获取平均值
        if (NTP.serverTimes.length >= NTP.requiredResponses) {
            var sumOffset = 0;
            var sumDelay = 0;
            var i = 0;
            for (i = 0; i < NTP.serverTimes.length; i++) {
                sumOffset += NTP.serverTimes[i];
                sumDelay += NTP.serverDelay[i];
            }
            var averageOffset = Math.round(sumOffset / i);
            var averageDelay = Math.round(sumDelay / i);
            storage.put("NTPClockOffset", averageOffset + '|' + NTP.fixTime()); // 保存获得offset时的时间戳
            storage.put("NTPClockDelay", averageDelay); // 保存获得offset时的时间戳
        } else {
            NTP.getServerTime();
        }
    },
    //获取服务器时间并判断是否获取成功
    getServerTime: function () {
        var NtpStartTime = NTP.getNow();
        storage.put("NtpStartTime", NtpStartTime);
        var res = http.get(NTP.serverUrl);
        if (res.statusCode !== 200) {
            toast("获取网络时间失败: " + res.statusCode + " " + res.statusMessage);
            return false;
        } else {
            NTP.parseServerResponse(res.body.json());
        }
    },
    //固定时间
    fixTime: function (timeStamp) {
        if (!timeStamp) {
            timeStamp = NTP.getNow();
        }
        var offset = storage.get("NTPClockOffset");
        try {
            if (!offset) {
                offset = 0;
            } else {
                offset = offset.split("|")[0];
            }
            if (isNaN(parseInt(offset, 10))) {
                return timeStamp;
            }
            return timeStamp + parseInt(offset, 10);
        } catch (e) {
            return timeStamp;
        }
    }
};




    // 获取默认开始时间
    function getTime() {
        var fmt = "YYYY-MM-dd hh:mm:ss";
        var d = new Date();
        var hh = d.getHours();
        var mm = d.getMinutes();
        var ss = d.getSeconds();
        if (mm < 30) {
            mm = 30
            ss = 00
        }
        else{
            hh+=1
            mm = 00
            ss = 00    
        }
        
        var o = {
            "Y+": d.getYear() + 1900,
            "M+": d.getMonth() + 1,
            "d+": d.getDate(),
            "h+": hh,
            // "m+": d.getMinutes(),
            // "s+": d.getSeconds()
            "m+": mm,
            "s+": ss
        };
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 4) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }
        fmt = fmt.replace(/-/g, '/');
        return fmt;
      };

      //定义初始化界面数据
      var storage = storages.create("tmalltaobaohelper.byfly");
      threads.start(NTP.sync);

      //初始化苏宁界面数据
    setTimeout(initConfig, 500);

    function initConfig() {  

        ui.startTime.setText(getTime());      
        ui.interval.setText(storage.get("interval", "100").toString());
        ui.lastTime.setText(storage.get("lastTime", "10").toString());      
        ui.delaytime.setText(storage.get("delaytime", "800").toString());       
      }
      //初始化淘宝界面
    setTimeout(initConfig_two, 500);
    function initConfig_two() {
        NTPClockOffset = storage.get("NTPClockOffset", "0");
        NTPClockDelay = storage.get("NTPClockDelay", "0");
    if (!NTPClockOffset) {
        NTPClockOffset = 0;
    } else {
        NTPClockOffset = parseInt(NTPClockOffset.split("|")[0]);
    }
    if (NTPClockOffset < 0) {
        var offset_str = "慢了" + -NTPClockOffset + 'ms，'
    } else {
        offset_str = "快了" + NTPClockOffset + 'ms，'
    }
    if (NTPClockDelay < 50) {
        var good_str = "网速评估:"+"您的网络延迟低于50ms,非常优秀！" 
    } 
    else if (NTPClockDelay < 100) {
        var good_str = "网速评估:"+"您的网络延迟低于100ms,优秀！" 
    } 
    else if (NTPClockDelay>100 && NTPClockDelay<200) {
        var good_str = "网速评估:"+"您的网络延迟高于100ms,抢购可能会有影响！" 
    } 
    else {
        good_str = "网速评估:"+"您的网络质量不佳，建议切换网络！" 
    }

    ui.networkTesttwo.on("click",function(){
        ui.networkTesttwo.setText("时间校准:"+"本地时间比淘宝" + offset_str +"已经为您校准了淘宝时间！"+'\n'+ "网络延迟：" + NTPClockDelay+'\n'+good_str );
        });       

        ui.startTime_two.setText(getTime());
        ui.interval.setText(storage.get("interval", "100").toString());
        ui.lastTime_two.setText(storage.get("lastTime_two", "10").toString());   
        ui.delaytime_two.setText(storage.get("delaytime_two", "200").toString()); 
        ui.count.setText(storage.get("count", "3").toString());

      }
      //自动付款支付宝
      function 自动付款(){
       
        }
      
    //初始化京东界面数据
      setTimeout(initConfig_tree, 500);
      function initConfig_tree() {

        ui.startTime_tree.setText(getTime());
        ui.interval.setText(storage.get("interval", "100").toString());
        ui.lastTime_tree.setText(storage.get("lastTime_tree", "10").toString());      
        ui.delaytime_tree.setText(storage.get("delaytime_tree", "800").toString());
        
      }
 //获取京东时间

 try{
    //执行的代码
    var thread = threads.start(function(){  //页面网络延时提示  
        /* timestamp1 = new Date().getTime();
        r = http.get("https://a.jd.com//ajax/queryServerData.html");
        timestamp2 = new Date().getTime()
        JDnetwork_delay = timestamp2-timestamp1  //网络延时
        var objj = r.body.json();
        JDtime_difference = timestamp1-objj.serverTime//网络时间差 
        if (JDtime_difference < 0) {
            var JDoffset_str = "慢了" + -JDtime_difference + 'ms，'
        } else {
            JDoffset_str = "快了" + JDtime_difference + 'ms，'
        }
        if (JDnetwork_delay < 50) {
            var JDgood_str = "网速评估:"+"您的网络延迟低于50ms,优秀啊老铁！" 
        } 
        else if (JDnetwork_delay < 100) {
            var JDgood_str = "网速评估:"+"您的网络延迟低于100ms,还可以！" 
        } 
        else if (JDnetwork_delay>100 && JDnetwork_delay<200) {
            var JDgood_str = "网速评估:"+"您的网络延迟高于100ms,抢购可能会有影响！" 
        } 
        else {
            JDgood_str= "网速评估:"+"您的网络质量不佳，建议切换网络！" 
        } */
        ui.networkTest_tree.on("click",function(){
            ui.networkTest_tree.setText("时间校准等待新接口开发");
            }); 
        
        });
}catch(e){
    log("异常错误获取京东时间") //错误处理,这样程序就不会崩溃,而且继续执行.

}

//获取苏宁时间
var thread2 = threads.start(function(){ 
    timestamp1 = new Date().getTime();
     recode_suning = http.get("http://quan.suning.com/getSysTime.do");  
    timestamp2 = new Date().getTime();
    SNnetwork_delay = timestamp2-timestamp1
    var  suningTime = recode_suning.body.json();
    var nowdate = suningTime.sysTime2;            
    var nowdate2 = nowdate.replace(/-/g,'/');
    var nowtime = new Date(nowdate2).getTime(); 
    SNtime_difference =timestamp1 - nowtime  ; 
    if (SNtime_difference < 0) {
        var SNoffset_str = "慢了" + -SNtime_difference + 'ms，'
    } else {
        SNoffset_str = "快了" + SNtime_difference + 'ms，'
    }
    if (SNnetwork_delay< 50) {
        var SNgood_str = "网速评估:"+"您的网络延迟低于50ms,优秀啊老铁！" 
    } 
    else if (SNnetwork_delay < 100) {
        var SNgood_str = "网速评估:"+"您的网络延迟低于100ms,还可以！" 
    } 
    else if (SNnetwork_delay>100 && SNnetwork_delay<200) {
        var SNgood_str = "网速评估:"+"您的网络延迟高于100ms,抢购可能会有影响！" 
    } 
    else {
        SNgood_str= "网速评估:"+"您的网络质量不佳，建议切换网络！" 
    }
    ui.networkTest.on("click",function(){
        ui.networkTest.setText("时间校准:"+"本地时间比苏宁" + SNoffset_str+"已经为您校准了苏宁时间！"+'\n'+"网络延时："+SNnetwork_delay+'\n'+SNgood_str);
        });
});

      // 时间戳转时间字符串
    function add0(m) {
        return m < 10 ? '0' + m : m
    }
    function getNow() {
        var now = new Date().getTime();
        return now - NTPClockOffset; 
    }

    function formatDate(needTime) {
        //needTime是整数，否则要parseInt转换
        var time = new Date(parseInt(needTime));
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        var S = time.getMilliseconds();
        return add0(h) + ':' + add0(mm) + ':' + add0(s)+":"+add0(S);
    }


      // 检测时间字符串是否有效
    function strDateTime(str) {
        var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
        var r = str.match(reg);
        if (r == null) return false;
        var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
        return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
    }
    
    // 苏宁程序主要逻辑1234
    ui.ok.click(function () {
        // 检查无障碍服务
        if (auto.service == null) {
            toast("请先开启无障碍服务！");
            return;
        }
    //接收界面数据
    startTime = ui.startTime.getText().toString();
   
    interval = parseInt(ui.interval.getText());
    lastTime = parseInt(ui.lastTime.getText());
    delaytime = parseInt(ui.delaytime.getText());
    if (!strDateTime(startTime)) {
        ui.startTime.setError("日期错误，请重新输入！");
        return;
    }
    //传递界面数据      
    storage.put("interval", interval);
    storage.put("lastTime", lastTime);
    storage.put("delaytime", delaytime);

    if(ui.ok.getText()=="开始运行") {
        ui.ok.setText("停止运行"); 
        
        model_change();
        device.keepScreenOn()//保持屏幕常亮
    }else{
        ui.ok.setText("开始运行");
        console.clear();
        console.hide();
        threads.shutDownAll();
        device.cancelKeepingAwake();   
        }
}); 
    function model_change()
    {
  
        if(平台类别2=="苏宁页面"){
            device.keepScreenOn();
            
            threads.start(main);
        }
        //1234
        if(平台类别2=="苏宁购物车"){
            device.keepScreenOn();
            
            threads.start(sn购物车);           
        } 
    }

    var storage3 = storages.create("这个是一个文件名2");
    for (i = 0; i < 7; i++) {
    var content2 = storage3.get("password_" + (i + 1));
    
    if (content2) {
        ui["password_" + (i + 1)].setText(content2);
    }
    }

    var storage6 = storages.create("这个是一个文件名6");
    for (i = 0; i < 2; i++) {
    var content6 = storage6.get("X" + (i + 1));
    
    if (content6) {
        ui["X" + (i + 1)].setText(content6);
    }}

    // 淘宝程序主要逻辑
    ui.ok_two.click(function () {
     // 检查无障碍服务
     if (auto.service == null) {
            toast("请先开启无障碍服务！");
            return;
        }
        arr = new Array();
        for (i = 0; i < 7; i++) {
        var content2 = ui["password_" + (i + 1)].getText() + "";
        storage3.put("password_" + (i + 1), content2);
        arr.push(content2);
        };

        arr6 = new Array();
        for (i = 0; i < 2; i++) {
        var content6 = ui["X" + (i + 1)].getText() + "";
        storage6.put("X" + (i + 1), content6);
        arr6.push(content6);
        };
    //接收界面数据
        startTime_two = ui.startTime_two.getText().toString();
        interval = parseInt(ui.interval.getText());
        count= parseInt(ui.count.getText());
        lastTime_two = parseInt(ui.lastTime_two.getText());
        delaytime_two = parseInt(ui.delaytime_two.getText());
        if (!strDateTime(startTime_two)) {
            ui.startTime_two.setError("日期错误，请重新输入！");
            return;
        }
        //传递界面数据      
        storage.put("interval", interval);
        storage.put("count", count);
        storage.put("lastTime_two", lastTime_two);
        storage.put("delaytime_two", delaytime_two);

        //按下开始运行

          if(ui.ok_two.getText()=="开始运行") {
            var X轴判断 = ui.X1.text();
            var Y轴判断 = ui.X2.text();        
            if(X轴判断.length==0&&连续提交=="有")
            {
                toast("您选择了连续提交模式，但未输入X轴坐标！")
                ui.X1.setError("您选择了连续提交模式，但未输入X轴坐标！")
                return;
            }
            if(Y轴判断.length==0&&连续提交=="有")
            {
                toast("您选择了连续提交模式，但未输入Y轴坐标！")
                ui.X2.setError("您选择了连续提交模式，但未输入Y轴坐标！")
                return;
            }
            if(X轴判断.length>=5&&连续提交=="有") {
                ui.X1.setError("您的坐标有误,请重新输入！");
                return;
            }     
            if(Y轴判断.length>=5&&连续提交=="有") {
                ui.X2.setError("您的坐标有误,请重新输入！");
                return;              
            } 
        if(连续提交=="无"||连续提交=="有"){
                ui.ok_two.setText("停止运行");    
                threads.start(main_two);
                device.keepScreenOn()//保持屏幕常亮
        }}else{
            ui.ok_two.setText("开始运行");
            console.clear();
            console.hide();
            threads.shutDownAll();
            device.cancelKeepingAwake();   
            }   
});


     // 京东程序主要逻辑
     ui.ok_tree.click(function () {
        // 检查无障碍服务
        if (auto.service == null) {
            toast("请先开启无障碍服务！");
            return;
    }

    //接收界面数据
    startTime_tree = ui.startTime_tree.getText().toString();
    interval = parseInt(ui.interval.getText());
    lastTime_tree = parseInt(ui.lastTime_tree.getText());
    delaytime_tree = parseInt(ui.delaytime_tree.getText());
    if (!strDateTime(startTime_tree)) {
        ui.startTime.setError("日期错误，请重新输入！");
        return;
    }
    //传递界面数据      
    storage.put("interval", interval);
    storage.put("lastTime_tree", lastTime_tree);
    storage.put("delaytime_tree", delaytime_tree);

       //按下开始运行
    if (ui.ok_tree.getText().toString() === '开始运行') {
        // 一直保持屏幕常亮
        device.keepScreenOn();
        model_change2();
        ui.ok_tree.setText('停止运行');
    } else {
        console.clear();
        console.hide();
        threads.shutDownAll();
        device.cancelKeepingAwake();
        ui.ok_tree.setText('开始运行');
    }

});  

function model_change2()
{
    if(平台类别=="京东页面"){
        device.keepScreenOn();
        
        threads.start(main_tree);
    }
    if(平台类别=="京东购物车"){
        device.keepScreenOn();
        threads.start(京东购物车);           
    } 
    if(平台类别=="京东BP链接"){
        device.keepScreenOn();
        threads.start(京东BP链接);           
    } 
}

      //这是苏宁主程序 
      function main() {
        var middle = device.width / 2 -400;      
        console.setPosition(middle, 0);
        console.setGlobalLogConfig({ "file": "/sdcard/shopping日志.txt" });
        console.show();
        var DetailPage =0;
        var notDetailPage = 0;
        var notInDetailPage = 0
        engines.execScriptFile("./css.js");
        logWithTime("欢迎使用shopping苏宁秒杀助手"); 
        sleep(800); 
        logWithTime("请勿用于非法用途");  
        sleep(800); 
        logWithTime("请进入所要抢购商品的详情页");
        sleep(800); 
           
        var startTime2 = new Date(Date.parse(startTime)).getTime();
        var endTime = new Date(startTime2.valueOf() + lastTime * 1000).getTime();
        var shoppingingtime = startTime2 - delaytime;


        reviewtime();
         //判断实际时间是否大于抢购时间
    function reviewtime(){
        var shijian = getNow();
           if (shijian > shoppingingtime) {
                console.warn("您的时间已经错过了哦,请重新输入时间！");
                sleep(2000);
                console.clear();
                console.hide();
                threads.shutDownAll();
            }
           if(shijian < shoppingingtime){
                logWithTime("您的抢购时间为：" + formatDate(shoppingingtime));
                logWithTime("距离抢购时间还剩"+(startTime2-shijian)/1000+"秒"+"请耐心等待");
                }
            }
             // 检测是否在商品详情页
    x = setInterval(function () {
        var t = getNow();
        if (t < shoppingingtime) {
            if (className("android.widget.TextView").text("已选").exists()) {
                if (DetailPage === 0) {
                    logWithTime("已进入商品详情页，请等待");
                    DetailPage++;
                    notDetailPage = 0
                }

            } else {
                if (notInDetailPage === 0) {
                    logWithTime("未进入商品详情页，请前往，否则无法进行购买！");
                    DetailPage = 0;
                    notInDetailPage++
                }
            }
        } else {
            not_in_Detail_Page = 0;  // 商品详情页状态复位
            clearInterval(x)
        }

    }, 500);

            
z = setInterval(function () {
    var t = getNow();
    if(t >= shoppingingtime && t < endTime){                
        logWithTime("开始抢购")
        苏宁页面();
        clearInterval(z);        
    }  
  },10)
};
function 苏宁页面()
{
    var Crowding = 0;

    var endTime = lastTime*1000;
    
           // 如果在抢购商品详情页面
        threads.start(function(){
            setInterval(function(){      
        if(className("android.widget.Button").text("立即抢购").exists()){
            logWithTime("准备点击抢购中");
            /* click("立即抢购"); */ 
            clicktext("立即抢购")
           /*  click("确定");
            click("提交订单");  */
            clicktext("确定")
            logWithTime("准备点击确定");       
          }
        }, 10);
        });  

        threads.start(function(){
            setInterval(function(){
            if(className("android.widget.TextView").text("立即抢购").exists())
            {
                logWithTime("准备点击抢购中");
                //click("立即抢购"); 
                clicktext("立即抢购");
               // click("提交订单"); 
               logWithTime("准备提交订单");   
               clicktext("提交订单");
                
            }   
        }, 10);
        });  

        threads.start(function(){
            setInterval(function(){  
        if(className("android.widget.TextView").textContains("立即购买").exists()){
            logWithTime("准备点击购买中");
            click("立即购买");
            click("确定");
            click("提交订单"); 
            logWithTime("准备点击确定");
        }
        }, 10);
        });  
        threads.start(function(){
            setInterval(function(){
        if(className("android.widget.TextView").textContains("马上抢").exists()){
            logWithTime("准备点击马上抢");
            click("马上抢")
            logWithTime("马上抢已点击");
            }
        }, 10);
        });  
             // 如果在确定界面
        threads.start(function(){
            setInterval(function(){
        if (className("android.widget.TextView").text("确定").exists()) {
            clicktext("确定");;
            logWithTime("确定已点击");
        }
        }, 10);
        });
            // 如果在提交订单界面
        threads.start(function(){
            setInterval(function(){
         if (className("android.widget.TextView").text("提交订单").exists()) {
            logWithTime("正在尝试提交订单");
            clicktext("提交订单");
            //click("提交订单");
            logWithTime("订单已提交");
        }
        }, 10);
        });
        threads.start(function(){
            setInterval(function(){
        if (className("android.widget.TextView").text("知道了").exists()) {
            className("android.widget.TextView").text("知道了").findOne().click();
            Crowding++;
            logWithTime("第" + Crowding + "次拥挤了，再试一次吧！");             
        }
        }, 10);
        });
            // 抢购成功
        threads.start(function(){
                setInterval(function(){
        if (className("android.widget.TextView").text("苏宁收银台").exists()) {
            logWithTime("抢购成功！请支付！");
            log("立即付款开始") 
            //开始火速付款
            click(xxx,yyy);
            sleep(50);
            click(xxx,yyy);
            var password_1 = ui.password_1.text()*1;    
            var password_2 = ui.password_2.text()*1;
            var password_3 = ui.password_3.text()*1;
            var password_4 = ui.password_4.text()*1;
            var password_5 = ui.password_5.text()*1;
            var password_6 = ui.password_6.text()*1; 
          // var 自动付款 ="有"
            threads.start(function(){
                setInterval(function(){
                if (className("android.widget.TextView").text("立即付款").exists()) {

                    if(自动付款1 == "无"){
                           
                            device.cancelKeepingAwake(); //关闭屏幕常亮
                            Panic_buying_end()             
                        }}
                        if(自动付款1 == "有")
                        {
                            click("立即付款")                            
                        } 
                    },200)
                })  
                var 密码1 = "真"
                var 密码2 = "假"
                var 密码3 = "假"
                var 密码4 = "假"
                var 密码5 = "假"
                var 密码6 = "假"
                threads.start(function(){
                    setInterval(function(){ 
                    if (className("android.widget.TextView").text("请输入支付密码").exists()) { 
                        if(密码1 == "真"&&className("android.widget.TextView").text(password_1).exists()){click(password_1);密码2 = "真";sleep(10)}
                        if(密码2 == "真"&&className("android.widget.TextView").text(password_2).exists()){click(password_2);密码3 = "真";sleep(10)}
                        if(密码3 == "真"&&className("android.widget.TextView").text(password_3).exists()){click(password_3);密码4 = "真";sleep(10)}
                        if(密码4 == "真"&&className("android.widget.TextView").text(password_4).exists()){click(password_4);密码5 = "真";sleep(10)}
                        if(密码5 == "真"&&className("android.widget.TextView").text(password_5).exists()){click(password_5);密码6 = "真";sleep(10)}
                        if(密码6 == "真"&&className("android.widget.TextView").text(password_6).exists()){click(password_6);Panic_buying_end()}
                    } 
                },300)
                })
            //1234
            device.cancelKeepingAwake(); 
            //Panic_buying_end();             
        }
        }, 10);
        });
        threads.start(function(){
            setInterval(function(){
            sleep(endTime)
            logWithTime("超出预定抢购时长，抢购结束");
            device.cancelKeepingAwake();
            Panic_buying_end();
        }, 10);
        });
}
 //这是淘宝主程序 
 function main_two() {
    var middle = device.width / 2 -400;      
    console.setPosition(middle, 0);
    console.setGlobalLogConfig({ "file": "/sdcard/shopping日志.txt" });
    console.show();
    var DetailPage =0;
    var notDetailPage = 0;
    var notInDetailPage = 0
    var notChecked = 0;

    engines.execScriptFile("./css.js");
    logWithTime("欢迎使用淘宝秒杀助手"); 
    sleep(800); 
    logWithTime("请勿用于非法用途");  
    sleep(800); 
    logWithTime("本模式属于淘宝购物车抢购模式");  
    sleep(800);
    logWithTime("请您进入购物车,否则无法进行购买！");
    sleep(800); 
       
    var startTime2 = new Date(Date.parse(startTime_two)).getTime();
    var endTime = new Date(startTime2.valueOf() + lastTime_two * 1000).getTime();
    var shoppingingtime = startTime2 - delaytime_two;

    reviewtime();
     //判断实际时间是否大于抢购时间
function reviewtime(){
    var tt = getNow();
       if (tt > shoppingingtime) {
            console.warn("您的时间已经错过了哦,请重新输入时间！");
            sleep(2000);
            console.clear();
            console.hide();
            threads.shutDownAll();
        }
       if (tt < shoppingingtime){
            logWithTime("您的抢购时间为：" + formatDate(shoppingingtime));
            logWithTime("距离抢购时间还剩"+(startTime2-tt)/1000+"秒"+"请耐心等待");
            }
        }
         // 检测是否在商品详情页
x = setInterval(function () {
    var t = getNow();
    if (t < shoppingingtime) {
        if (className("android.widget.TextView").text("合计:").exists() || className("android.widget.TextView").text("全选").exists()) {
            if (DetailPage === 0) {
                logWithTime("已进入购物车，请耐心等待...");
                DetailPage++;
                notDetailPage = 0
            }

        } else {
            if (notInDetailPage === 0) {
                logWithTime("未进入购物车，请前往，否则无法进行购买！");
                DetailPage = 0;
                notInDetailPage++
            }
        }
    } else {
        not_in_Detail_Page = 0;  // 商品详情页状态复位
        clearInterval(x)
    }
    //判断是否勾选商品
    if(提前刷新=="有")
    {
        if (notChecked === 0){
            notChecked = 1
        logWithTime("请您勿勾选商品！");
        logWithTime("需要提前刷新，将自动隐藏控制台！");
sleep(1000)
                console.hide()
        }
    } 
 /*    if(手动勾选 == "有"){
        if (className("android.widget.TextView").text("结算").exists()) {
                found = true;
            if (notChecked === 0){
                notChecked = 1
                text("全选").findOne().click()
                logWithTime("检测到您未勾选商品，以为您自动勾选！");
                //自动勾选
            }
        }
    }  
    else{
        if (notChecked === 0){
            notChecked = 1
        logWithTime("请您勿勾选商品！");
        }
    } */
}, 500);
z = setInterval(function () {
    var t = getNow();
    if(t >= shoppingingtime && t < endTime){                
        logWithTime("开始抢购")
        淘宝购物车();
        clearInterval(z);        
    }  
  },10)     
};
function 淘宝购物车()
{
    var i = 1;
    var Crowding = 0;
    var Success = 0;
    var found = false;
    var endTime = lastTime_two * 1000
    //这里是密码
    var password_1 = ui.password_1.text()*1;    
    var password_2 = ui.password_2.text()*1;
    var password_3 = ui.password_3.text()*1;
    var password_4 = ui.password_4.text()*1;
    var password_5 = ui.password_5.text()*1;
    var password_6 = ui.password_6.text()*1;
    var 提交订单X轴 = ui.X1.text()*1;
    var 提交订单Y轴 = ui.X2.text()*1;
    var 价格值 = ui.password_7.text()
    var count = ui.count.text()*1
    if(提前刷新=="有"){
        threads.start(function(){
            setInterval(function(){
                if(开启刷新=="有"){
                if(className("android.widget.TextView").text("结算"))
                {
                    logWithTime("开始刷新");
                    gesture(400, [500, 300], [500, 900])
                    logWithTime("已刷新");
                    //toast("已经刷新,关闭控制台")
                    开启刷新 = "无"
                }
                }
            },10)
        })
        
        threads.start(function(){
            setInterval(function(){
         if(className("android.widget.TextView").text("加载完成").exists()){
            logWithTime("准备勾选");
            className("android.view.View").desc("勾选按钮，商品未选中，双击选中商品").findOne().click()
            logWithTime("已勾选");
            }
        },10)
        })
        }      

    if(自动勾选 == "有"){
        var 全选 = "有"
        threads.start(function(){
            setInterval(function(){ 
            if(全选 == "有"){
        if (className("android.widget.CheckBox").text("全选").exists()&&className("android.widget.TextView").textContains("结算").exists()) { 
            text("全选").findOne().click() 
            全选 = "无"
        }}
        },100)
        })

        var 校验价格 = "真"
        if(校验价格 == "真"){
            threads.start(function(){
                setInterval(function(){ 
                if(className("android.widget.TextView").text("￥"+价格值).depth(15).exists()&&className("android.widget.TextView").textContains("结算").exists())
                {
                    logWithTime("已找到符合预定价格的商品，开始结算！");
                    className("android.widget.TextView").textContains("结算").findOne().click();
                }        
                else if(className("android.widget.TextView").textContains("结算(0").exists())
                {
                    全选 = "有"
                    logWithTime("未找到符合预定价格的商品，不结算，取消再次勾选！");
                    desc("取消全选").findOne().click()
                }          
        },200)
        })
        }
        }else
        {
            threads.start(function(){
                setInterval(function(){
                    //结算点击不了,用坐标点击5678
            if (className("android.widget.TextView").textContains("结算").exists()) {      
                   logWithTime("准备点击结算");
                  // className("android.widget.TextView").textContains("结算").findOne().click();
                  clicktextContains("结算")
                   found = true; 
                   logWithTime("结算已点击"); 
                   if(测试 =="有") 
                   {    sleep(100) 
                       logWithTime("测试模式不提交订单！");
                       Panic_buying_end();
                   }      
                }
            },10)
            })
        }

    threads.start(function(){
        setInterval(function(){ 
    if (className("android.widget.TextView").text("失效宝贝").exists() && className("android.widget.TextView").text("商品不能购买").exists()&&count>0) {
        logWithTime("检测到商品已失效或无法购买，即将返回结算界面开始重试！");
            logWithTime("已返回结算界面，准备重试！");
            sleep(random(10,30))
            back();
            count = count - 1;
            logWithTime("已重试"+i+"次");
            i++;
    }
    }, 100);
    });
    //不测试时才提交订单
    var 提交订单 = "真"
    if(测试 =="无"&&连续提交=="有") { 
        threads.start(function(){
            setInterval(function(){
    if(className("android.widget.TextView").textContains("合计").exists()&&className("android.widget.TextView").textContains("配送").exists()&&提交订单 == "真")
        {
            var x=1             
        while(true){
            if(x<50){
                press(提交订单X轴,提交订单Y轴,10)
                //clicktext("提交订单")
                x++;
                logWithTime("正在尝试提交订单");
            }
        if(x==50){
            break
            }
         }
         提交订单 = "假"
        }
        },10)
        })
        }
        if(测试 =="无"&&连续提交=="无") { 
            threads.start(function(){
                setInterval(function(){ 
                    //56781
                    if (className("android.widget.TextView").textContains("合计").exists()&&className("android.widget.TextView").textContains("配送").exists()) {
                        logWithTime("正在尝试提交订单");
                        //className = android.widget.FrameLayoutdepth = 10drawingOrder = 3
                       // className("android.widget.TextView").text("提交订单").findOne().click();
                 
                       var x=1             
                       while(true){
                           if(x<50){
                               press(提交订单X轴,提交订单Y轴,10)
                               //clicktext("提交订单")
                               x++;
                               logWithTime("正在尝试提交订单");
                           }
                       if(x==50){
                           break
                           }
                        }
                        提交订单 = "假"           
                        }
                    
            }, 10);
            });
            }
        threads.start(function(){
            setInterval(function(){
        if (className("android.widget.TextView").textContains("加载中").exists()) {
            if (Crowding === 0){
                Crowding = 1
                logWithTime("页面加载中");
                }
                found = true;            
            }
        }, 10);
    });


    threads.start(function(){
        setInterval(function(){ 
    if (className("android.widget.TextView").text("立即付款").exists()) {
        if(自动付款 == "无"){
                logWithTime("抢购成功！请支付！");
                found = true;
                Success++;
                device.cancelKeepingAwake();  
                Panic_buying_end();             
            }}
            if(自动付款 == "有")
            {
                click("立即付款") 
            }
        }, 200);
    });
    var 密码1 = "真"
    var 密码2 = "假"
    var 密码3 = "假"
    var 密码4 = "假"
    var 密码5 = "假"
    var 密码6 = "假"
    threads.start(function(){
        setInterval(function(){ 
        if (className("android.widget.TextView").text("请输入支付密码").exists()) { 
            if(密码1 == "真"&&className("android.widget.TextView").text(password_1).exists()){click(password_1);密码2 = "真";sleep(10)}
            if(密码2 == "真"&&className("android.widget.TextView").text(password_2).exists()){click(password_2);密码3 = "真";sleep(10)}
            if(密码3 == "真"&&className("android.widget.TextView").text(password_3).exists()){click(password_3);密码4 = "真";sleep(10)}
            if(密码4 == "真"&&className("android.widget.TextView").text(password_4).exists()){click(password_4);密码5 = "真";sleep(10)}
            if(密码5 == "真"&&className("android.widget.TextView").text(password_5).exists()){click(password_5);密码6 = "真";sleep(10)}
            if(密码6 == "真"&&className("android.widget.TextView").text(password_6).exists()){click(password_6);Panic_buying_end()}
        } 
    },300)
    })
    threads.start(function(){
        setInterval(function(){ 
        if (className("android.view.View").desc("查看订单").findOne().parent().exists()) { 
            logWithTime("支付成功！");
            Panic_buying_end()
        }
    },10)
    })  
    threads.start(function(){
        setInterval(function(){ 
        sleep(endTime)
        logWithTime("超出预定抢购时长，抢购结束");
        device.cancelKeepingAwake();
        Panic_buying_end();           
    }, 10);
    });  
}
//这是京东主程序 
function main_tree() {
    var middle = device.width / 2 -400;      
    console.setPosition(middle, 0);
    console.setGlobalLogConfig({ "file": "/sdcard/shopping日志.txt" });
    console.show();
    var DetailPage =0;
    var notDetailPage = 0;
    var notInDetailPage = 0

    logWithTime("欢迎使用shopping京东秒杀助手"); 
    engines.execScriptFile("./css.js");
    sleep(800); 
    logWithTime("请勿用于非法用途");  
    sleep(800); 
    logWithTime("请您进入商品详情页,否则无法进行购买！");
    sleep(800); 
       
    var startTime2 = new Date(Date.parse(startTime_tree)).getTime();
    var endTime = new Date(startTime2.valueOf() + lastTime_tree* 1000).getTime();
    var shoppingingtime = startTime2 - delaytime_tree;


    reviewtime();
     //判断实际时间是否大于抢购时间
function reviewtime(){
    var tt = getNow();
       if (tt > shoppingingtime) {
            console.warn("您的时间已经错过了哦,请重新输入时间！");
            sleep(2000);
            console.clear();
            console.hide();
            threads.shutDownAll();
        }
       if (tt < shoppingingtime){
            logWithTime("您的抢购时间为：" + formatDate(shoppingingtime));
            logWithTime("距离抢购时间还剩"+(startTime2-tt)/1000+"秒"+"请耐心等待");
            }
        }
         // 检测是否在商品详情页
x = setInterval(function () {
    var t = getNow();
    if (t < shoppingingtime) {
        if (className("android.widget.LinearLayout").clickable(true).depth(9).exists()) {
            if (DetailPage === 0) {
                logWithTime("已进入商品详情页，请耐心等待...");
                DetailPage++;
                notDetailPage = 0
            }

        } else {
            if (notInDetailPage === 0) {
                logWithTime("未进入商品详情页或者处于预购商品界面等待立即抢购，请前往，否则无法进行购买！");
                DetailPage = 0;
                notInDetailPage++
            }
        }
    } else {
        not_in_Detail_Page = 0;  // 商品详情页状态复位
        clearInterval(x)
    }
}, 500);
    
z = setInterval(function () {
    var t = getNow();
    if(t >= shoppingingtime && t < endTime){                
        logWithTime("开始抢购")
        京东页面();
        clearInterval(z);        
    }  
  },10)
};
function 京东页面()
{
    var endTime = lastTime_tree * 1000;
    var Crowding = 0;
    threads.start(function(){
        setInterval(function(){
            if (text("立即抢购").exists()) {
                logWithTime("准备点击抢购");
                //click("立即抢购")
                clicktext("立即抢购"); 
                logWithTime("立即抢购已点击");           
             }
            },10)
        })
        threads.start(function(){
            setInterval(function(){
            if (text("立即购买").exists()) {
                logWithTime("准备点击购买");
                //click("立即购买")
                clicktext("立即购买");
                logWithTime("立即购买已点击");           
                } 
            },10)
        }) 
        threads.start(function(){
            setInterval(function(){
                if (textContains("领券购买").exists()) {
                    textContains("领券购买").findOne().click();
                    logWithTime("领券购买已点击"); 
                     }
             
            },10)
        }) 
        threads.start(function(){
            setInterval(function(){  
            if (text("提交订单").exists()) {
                    logWithTime("页面加载中");
                    logWithTime("正在尝试提交订单");
                    //click("提交订单");
                    clicktext("提交订单");
                    logWithTime("订单已提交");             
                }
            },10)
        }) 
        threads.start(function(){
            setInterval(function(){  
            if (text("帮我付").exists()) {
                    logWithTime("准备点击帮我付");
                   //click("提交订单");
                    clicktext("帮我付");
                    logWithTime("订单已提交");             
                }
            },10)
        }) 
        threads.start(function(){
            setInterval(function(){ 
            if (text("我知道了").exists()) {
                    //click("我知道了")
                    clicktext("我知道了");
                    Crowding++;
                    logWithTime("第" + Crowding + "次拥挤了，再试一次吧！");             
                    }
                },10)
            }) 
        threads.start(function(){
            setInterval(function(){ 
            if (text("确定").exists()) {
                        logWithTime("准备点击确定"); 
                        //click("确定")
                        clicktext("确定"); 
                        logWithTime("确定已点击");           
                     }
                    },10)
                }) 
        threads.start(function(){
            setInterval(function(){ 
            if (className("android.widget.TextView").text("京东收银台").exists()||className("android.widget.TextView").text("发送代付请求").exists()) {
                        logWithTime("抢购成功！请返回支付或者直接用另一个号付款！");
                        device.cancelKeepingAwake(); 
                        Panic_buying_end();              
                    }
                },10)
            })  
        threads.start(function(){
            setInterval(function(){ 
                sleep(endTime) 
                logWithTime("超出预定抢购时长，抢购结束");
                device.cancelKeepingAwake();
                Panic_buying_end(); 
            },10)
        })                          
}
      //这是苏宁购物车主程序 
      function sn购物车() {
        var middle = device.width / 2 -400;      
        console.setPosition(middle, 0);
        console.setGlobalLogConfig({ "file": "/sdcard/shopping日志.txt" });
        console.show();
        var DetailPage =0;
        var notDetailPage = 0;
        var notInDetailPage = 0
engines.execScriptFile("./css.js");
        logWithTime("欢迎使用shopping苏宁秒杀助手"); 
        sleep(800); 
        logWithTime("请勿用于非法用途");  
        sleep(800); 
        logWithTime("请进入购物车");
        sleep(800); 
           
        var startTime2 = new Date(Date.parse(startTime)).getTime();
        var endTime = new Date(startTime2.valueOf() + lastTime * 1000).getTime();
        var shoppingingtime = startTime2 + delaytime;


        reviewtime();
         //判断实际时间是否大于抢购时间
    function reviewtime(){
        var shijian = getNow();
           if (shijian > shoppingingtime) {
                console.warn("您的时间已经错过了哦,请重新输入时间！");
                sleep(2000);
                console.clear();
                console.hide();
                threads.shutDownAll();
            }
           if(shijian < shoppingingtime){
                logWithTime("您的抢购时间为：" + formatDate(shoppingingtime));
                logWithTime("距离抢购时间还剩"+(startTime2-shijian)/1000+"秒"+"请耐心等待");
                }
            }
             // 检测是否在商品详情页
    x = setInterval(function () {
        var t = getNow();
        if (t < shoppingingtime) {
            if (className("android.widget.TextView").text("购物车").exists()) {
                if (DetailPage === 0) {
                    logWithTime("已进入购物车，请等待");
                    DetailPage++;
                    notDetailPage = 0
                }

            } else {
                if (notInDetailPage === 0) {
                    logWithTime("未进入购物车，请前往，否则无法进行购买！");
                    DetailPage = 0;
                    notInDetailPage++
                }
            }
        } else {
            not_in_Detail_Page = 0;  // 商品详情页状态复位
            clearInterval(x)
        }

    }, 500);

    z = setInterval(function () {
        var t = getNow();
        if(t >= shoppingingtime && t < endTime){                
            logWithTime("开始抢购")
            SN购物车();
            clearInterval(z);        
        }  
      },100)
 
};
function SN购物车()
{
    var  Crowding = 0;
    var endTime = lastTime * 1000;
         // 如果在购物车
         var 勾选 = "有"
        threads.start(function(){
        setInterval(function(){
            if(勾选 =="有"){
        if(className("android.widget.CheckBox").enabled(true).exists()){
          className("android.widget.CheckBox").enabled(true).findOne().click()
            勾选 = "无"
            click("去结算")
            click("提交订单")
        }}
        },10)
        })
       //    如果在提交订单界面
    threads.start(function(){
        setInterval(function(){
        if (className("android.widget.TextView").text("提交订单").exists()) {
            logWithTime("正在尝试提交订单");
            click("提交订单");
            logWithTime("订单已提交");
        }
        }, 10);
    });
         threads.start(function(){
            setInterval(function(){
                if(className("android.widget.TextView").textContains("去结算").exists()){
                    logWithTime("正在尝试结算");
                    click("去结算")
                    sleep(random(10,25)) 
                    logWithTime("已结算");
                  }
                  if(className("android.widget.TextView").text("去结算(2)").exists()){
                    logWithTime("正在尝试结算");
                    click("去结算")
                    sleep(random(10,25)) 
                    logWithTime("已结算");
                   }
                   if(className("android.widget.TextView").text("去结算(3)").exists()){
                    logWithTime("正在尝试结算");
                    click("去结算")
                    sleep(random(10,25)) 
                    logWithTime("已结算");
                   }
                }, 50);
            });
            //需要领卷购买
            threads.start(function(){
                setInterval(function(){
             if(className("android.widget.TextView").textContains("领券结算").exists()){
                logWithTime("正在尝试结算");
                click("领券结算")
                sleep(random(10,25)) 
                logWithTime("已结算");
             }
             if(className("android.widget.TextView").text("领券结算(2)").exists()){
               logWithTime("正在尝试结算");
               click("领券结算(2)")
               sleep(random(10,25)) 
               logWithTime("已结算");
             }
             if(className("android.widget.TextView").text("领券结算(3)").exists()){
                logWithTime("正在尝试结算");
                click("领券结算(3)")
                sleep(random(10,25)) 
                logWithTime("已结算");
             }
             }, 50);
             });
    threads.start(function(){
        setInterval(function(){
            if (className("android.widget.TextView").text("知道了").exists()) {
                className("android.widget.TextView").text("知道了").findOne().click();
                Crowding++;
                logWithTime("第" + Crowding + "次拥挤了，再试一次吧！");             
            }
        }, 200);
    });    
            // 抢购成功,自动付款1234
           
    threads.start(function(){
        setInterval(function(){
         if (className("android.widget.TextView").text("苏宁收银台").exists()) {
            logWithTime("抢购成功！请支付！");
             log("立即付款开始") 
        
     
             //开始火速付款
             click(xxx,yyy);
             sleep(50);
             click(xxx,yyy);
             var password_1 = ui.password_1.text()*1;    
             var password_2 = ui.password_2.text()*1;
             var password_3 = ui.password_3.text()*1;
             var password_4 = ui.password_4.text()*1;
             var password_5 = ui.password_5.text()*1;
             var password_6 = ui.password_6.text()*1; 
       // var 自动付款 ="有"
        threads.start(function(){
            setInterval(function(){
            if (className("android.widget.TextView").text("立即付款").exists()) {
                if(自动付款1 == "无"){
                        logWithTime("抢购成功！请支付！");
                        device.cancelKeepingAwake(); //关闭屏幕常亮
                        Panic_buying_end()             
                    }}
                    if(自动付款1 == "有")
                    {
                        click("立即付款")                            
                    } 
                },200)
            })  
            var 密码1 = "真"
            var 密码2 = "假"
            var 密码3 = "假"
            var 密码4 = "假"
            var 密码5 = "假"
            var 密码6 = "假"
            threads.start(function(){
                setInterval(function(){ 
                if (className("android.widget.TextView").text("请输入支付密码").exists()) { 
                    if(密码1 == "真"&&className("android.widget.TextView").text(password_1).exists()){click(password_1);密码2 = "真";sleep(10)}
                    if(密码2 == "真"&&className("android.widget.TextView").text(password_2).exists()){click(password_2);密码3 = "真";sleep(10)}
                    if(密码3 == "真"&&className("android.widget.TextView").text(password_3).exists()){click(password_3);密码4 = "真";sleep(10)}
                    if(密码4 == "真"&&className("android.widget.TextView").text(password_4).exists()){click(password_4);密码5 = "真";sleep(10)}
                    if(密码5 == "真"&&className("android.widget.TextView").text(password_5).exists()){click(password_5);密码6 = "真";sleep(10)}
                    if(密码6 == "真"&&className("android.widget.TextView").text(password_6).exists()){click(password_6);Panic_buying_end()}
                } 
            },300)
            })
            device.cancelKeepingAwake(); 
            //Panic_buying_end()             
        }
        }, 200);
    });    
    threads.start(function(){
        setInterval(function(){
            sleep(endTime)
            logWithTime("超出预定抢购时长，抢购结束");
            device.cancelKeepingAwake();
            Panic_buying_end();
        },200)
    });   
}


//京东购物车模式
function 京东购物车() {
    var middle = device.width / 2 -400;      
    console.setPosition(middle, 0);
    console.setGlobalLogConfig({ "file": "/sdcard/shopping日志.txt" });
    console.show();
    var DetailPage =0;
    var notDetailPage = 0;
    var notInDetailPage = 0
    var notChecked = 0
engines.execScriptFile("./css.js");
    logWithTime("欢迎使用shopping京东秒杀助手"); 
    sleep(800); 
    logWithTime("请勿用于非法用途");  
    sleep(800); 
    logWithTime("请您进入购物车,否则无法进行购买！");
    sleep(800); 
       
    var startTime2 = new Date(Date.parse(startTime_tree)).getTime();
    var endTime = new Date(startTime2.valueOf() + lastTime_tree* 1000).getTime();
    var shoppingingtime = startTime2 - delaytime_tree;


    reviewtime();
     //判断实际时间是否大于抢购时间
function reviewtime(){
    var tt = getNow();
       if (tt > shoppingingtime) {
            console.warn("您的时间已经错过了哦,请重新输入时间！");
            sleep(2000);
            console.clear();
            console.hide();
            threads.shutDownAll();
        }
       if (tt < shoppingingtime){
            logWithTime("您的抢购时间为：" + formatDate(shoppingingtime));
            logWithTime("距离抢购时间还剩"+(startTime2-tt)/1000+"秒"+"请耐心等待");
            }
        }
         // 检测是否在商品详情页
x = setInterval(function () {
    var t = getNow();
    if (t < shoppingingtime) {
        if (className("android.widget.TextView").text("购物车").depth(14).exists()) {
            if (DetailPage === 0) {
                logWithTime("已进入购物车，请耐心等待...");
                DetailPage++;
                notDetailPage = 0
            }

        } else {
            if (notInDetailPage === 0) {
                logWithTime("未进入购物车，请前往，否则无法进行购买！");
                DetailPage = 0;
                notInDetailPage++
            }
        }
    } else {
        not_in_Detail_Page = 0;  // 商品详情页状态复位
        clearInterval(x)
    }

    if (className("android.widget.TextView").text("去结算(0)").exists()) {
        if (notChecked === 0){
            notChecked = 1
            logWithTime("检测到您未勾选商品，将自动为您勾选！");
            //click("全选")
            clicktext("全选");
        }
        }
}, 500);
    
z = setInterval(function () {
    var t = getNow();
    if(t >= shoppingingtime && t < endTime){                
        logWithTime("开始抢购")
        购物车();
        clearInterval(z);        
    }  
  },10)
};
function 购物车()
{
    var endTime = lastTime_tree * 1000;
    var Crowding = 0

    threads.start(function(){
        setInterval(function(){
    if (className("android.widget.TextView").textContains("去结算").exists()) {   
        logWithTime("准备结算");   
        
        className("android.widget.TextView").textContains("去结算").findOne().click();   
        logWithTime("已结算，准备进入提交订单页面！");
     }
    },10)
    }) 
    threads.start(function(){
        setInterval(function(){ 
    if (className("android.widget.TextView").textContains("填写订单").exists()) {
        if (Crowding === 0){
            Crowding = 1
            logWithTime("页面加载中");
            }           
        }
    }, 10);
    });
    threads.start(function(){
        setInterval(function(){
            if (className("android.widget.Button").text("提交订单").exists()) {
                logWithTime("正在尝试提交订单");
                className("android.widget.Button").text("提交订单").findOne().click();
                logWithTime("订单已提交！");        
                }
        },10)
    }) 
    threads.start(function(){
        setInterval(function(){
            if (className("android.widget.Button").text("帮我付").exists()) {
                logWithTime("正在尝试提交订单");
                clicktext("帮我付");
                logWithTime("订单已提交！");        
                }
        },10)
    }) 

        threads.start(function(){
            setInterval(function(){ 
            if (className("android.widget.TextView").text("京东收银台").exists()||className("android.widget.TextView").text("发送代付请求").exists()) {
                        logWithTime("抢购成功！请支付！");
                        device.cancelKeepingAwake(); 
                        Panic_buying_end();              
                    }
                },10)
            })  
        threads.start(function(){
            setInterval(function(){ 
                sleep(endTime) 
                logWithTime("超出预定抢购时长，抢购结束");
                device.cancelKeepingAwake();
                Panic_buying_end(); 
            },10)
        })                          
}


//京东bp链接
function 京东BP链接() {
    var middle = device.width / 2 -400;      
    console.setPosition(middle, 0);
    console.setGlobalLogConfig({ "file": "/sdcard/shopping日志.txt" });
    console.show();
    var DetailPage =0;
    var notDetailPage = 0;
    var notInDetailPage = 0
    var notChecked = 0

    logWithTime("欢迎使用shopping京东秒杀助手"); 
    sleep(800); 
    logWithTime("请勿用于非法用途");  
    sleep(800); 
    logWithTime("请您确认已打开BP链接,否则无法进行购买！");
    sleep(800); 
       
    var startTime2 = new Date(Date.parse(startTime_tree)).getTime();
    var endTime = new Date(startTime2.valueOf() + lastTime_tree* 1000).getTime();
    var shoppingingtime = startTime2 - delaytime_tree;


    reviewtime();
     //判断实际时间是否大于抢购时间
function reviewtime(){
    var tt = getNow();
       if (tt > shoppingingtime) {
            console.warn("您的时间已经错过了哦,请重新输入时间！");
            sleep(2000);
            console.clear();
            console.hide();
            threads.shutDownAll();
        }
       if (tt < shoppingingtime){
            logWithTime("您的抢购时间为：" + formatDate(shoppingingtime));
            logWithTime("距离抢购时间还剩"+(startTime2-tt)/1000+"秒"+"请耐心等待");
            }
        }
         // 检测是否在商品详情页
x = setInterval(function () {
    var t = getNow();
    if (t < shoppingingtime) {
        if (className("android.widget.TextView").text("确认订单").depth(11).exists()) {
            if (DetailPage === 0) {
                logWithTime("已进入BP链接，请耐心等待...");
                DetailPage++;
                notDetailPage = 0
            }

        } else {
            if (notInDetailPage === 0) {
                logWithTime("未进入BP链接，请前往，否则无法进行购买！");
                DetailPage = 0;
                notInDetailPage++
            }
        }
    } else {
        not_in_Detail_Page = 0;  // 商品详情页状态复位
        clearInterval(x)
    }
}, 500);
    
z = setInterval(function () {
    var t = getNow();
    if(t >= shoppingingtime && t < endTime){                
        logWithTime("开始抢购")
        bp支付()
        clearInterval(z);        
    }  
  },10)
};
function bp支付()
{
    var endTime = lastTime_tree * 1000;

    threads.start(function(){
        setInterval(function(){
        if(className("android.view.View").text("微信支付").exists()){
            logWithTime("准备点击微信支付");
            className("android.view.View").text("微信支付").findOne().click()
            logWithTime("已点击微信支付");
            }
    },10)
    }) 

        threads.start(function(){
            setInterval(function(){ 
            if (className("android.view.ViewGroup").depth(17).exists()) {
                        logWithTime("抢购成功！请支付！");
                        device.cancelKeepingAwake(); 
                        Panic_buying_end();              
                    }
                },10)
        })  
        threads.start(function(){
            setInterval(function(){ 
                sleep(endTime) 
                logWithTime("超出预定抢购时长，抢购结束");
                device.cancelKeepingAwake();
                Panic_buying_end(); 
            },10)
        })                          
}

function 获取坐标(){
    console.show()
    console.info("请前往提交订单页面，否则无法获取坐标！")
    sleep(1000)
    console.info("30秒内未进入提交订单页面，获取坐标就会自动停止！")
    var 找按钮 = "有"
    threads.start(function(){
    setInterval(function(){ 
        if(className("android.widget.FrameLayout").depth("10").drawingOrder("3").indexInParent("1").exists()&&找按钮=="有"){
        var 提交订单= className("android.widget.FrameLayout").depth("10").drawingOrder("3").indexInParent("1").findOne()
        console.info("您的X轴坐标是:"+提交订单.bounds().centerX(),"\n您的Y轴坐标是:"+提交订单.bounds().centerY())
        找按钮="无"
        console.info("获取坐标成功！")
        threads.shutDownAll();
        }
    }, 100);
    }); 

    threads.start(function(){
        setInterval(function(){ 
            sleep(30000)
            console.info("获取坐标超时，已停止！")
            console.clear();
            console.hide();
            threads.shutDownAll();
            device.cancelKeepingAwake();   
        }, 100);
        }); 
    }
//=====================================================================================拼多多
ui.pinduoduo.on("click", () => {
    "ui";
    var ColoredButton = (function() {
        //继承ui.Widget
        util.extend(ColoredButton, ui.Widget);
    
        function ColoredButton() {
            //调用父类构造函数
            ui.Widget.call(this);
            //自定义属性color，定义按钮颜色
            this.defineAttr("color", (view, name, defaultGetter) => {
                return this._color;
            }, (view, name, value, defaultSetter) => {
                this._color = value;
                view.attr("backgroundTint", value);
            });
    
        }
        ColoredButton.prototype.render = function() {
            return (
                <button textSize="16sp" style="Widget.AppCompat.Button.Colored" w="*" h="auto"/>
            );
        }
    
        ui.registerWidget("colored-button", ColoredButton);
        return ColoredButton;
    })();
    var color = "#009688";
    ui.statusBarColor("#2F4F4F")
    ui.layout(
        <drawer id="drawer" >
            <vertical>
                <appbar>
                    <toolbar  id="toolbar"paddingTop="5dp" title="拼多多抢卷模式" background="#4C484C" />
                </appbar>
           
                <viewpager id="viewpager">
                    //这是拼多多界面
                    <frame background="#4C484C"> //start
                    <ScrollView>
                    <vertical>
                    <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="13sp"/>
                   
                    <TextView id="tv_text" marginLeft="10dp" marginRight="10dp" singleLine="true"  ellipsize="marquee" focusable="true" textColor="red" text="拼多多：目前只支持抢卷哦！ 软件已默认校准拼多多时间！全自动为你服务">
                    </TextView>
                  
                    <card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="40">
    

<radiogroup orientation="horizontal">
                    <radio id="model_pdd" text="抢卷模式" checked="true"/>
                    </radiogroup>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
    
<card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    

<horizontal>
                    <text textSize="13sp" textColor="black" text="  提前抢购时间"/>
                    <input id="delaytime_pdd" textColor="gray" inputType="number" text="200" w="80"/>
                    <text textSize="13sp" textColor="black" text="毫秒"  />
                    </horizontal>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
    
<card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    

<horizontal>
                    <text textSize="13sp" textColor="black" text="  页面抢卷频率" />
                    <input id="pinlv_pdd" textColor="gray" inputType="number" text="10" w="80"/>
                    <text textSize="13sp" textColor="black" text="毫秒"  />
                    </horizontal>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
    
<card w="*" h="50" margin="10 5" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="50">
    
<horizontal>
                    <text textSize="13sp" textColor="black" text="抢购持续时间" />
                    <input id="lastTime_pdd" textColor="gray" inputType="number" text="10" w="80"/>
                    <text textSize="13sp" textColor="black" text="秒"  />
                    </horizontal>
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
    
<card w="*" h="80" margin="10 5"cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
<vertical  h="80">
    
<text  textSize="13sp" textColor="black" text="  请输入抢购时间,格式为：2021/01/14 12:00:00"/> 
                    <input hint="  请在这里输入抢购时间，格式必须正确。" textColor="gray" id="startTime_pdd" /> 
</vertical>
<View bg="#EC6F54" h="80" w="5" />
</card>
                    //定义按钮的大小颜色和文本
                    <colored-button  id="ok_pdd"      layout_gravity="center"     style="Widget.AppCompat.Button.Colored"  text="开始运行"/>
                    </vertical>
                    </ScrollView>
                    </frame> //end
    
                </viewpager>        
            </vertical>
        </drawer>
    );
    ui.tv_text.setSelected(true);
    //这里是无障碍触发方式
    ui.autoService.on("check", function(checked) {
        // 用户勾选无障碍服务的选项时，跳转到页面让用户去开启 
        if(checked && auto.service == null) { 
         app.startActivity({
         action: "android.settings.ACCESSIBILITY_SETTINGS"  }); } 
          if(!checked && auto.service != null){ 
         auto.service.disableSelf();    }    }); 
       // 当用户回到本界面时，resume事件会被触发
         ui.emitter.on("resume", function() {
        // 此时根据无障碍服务的开启情况，同步开关的状态 
        ui.autoService.checked = auto.service != null;    }); 
    
         // 获取时分秒用于记录日志
         function logWithTime(msg) {
            console.info(formatDate(getNow()) + " " + msg);
           }
       
           // 获取时分秒用于记录日志
        function logWithTime(msg) {
            console.info(formatDate(getNow()) + " " + msg);
           }
       
           // 检测淘宝网络延迟和时间偏差
           try{
            //执行的代码
            var NTP = {
                requiredResponses: 3,
                serverTimes: [],//服务器时间
                serverDelay: [],//服务器延迟
                serverUrl: "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp",
                resyncTime: 0, // minutes
                sync: function () {
                    var offset = storage.get("NTPClockOffset");//获取时钟偏移
                    if (offset) {
                        try {
                            var t = offset.split("|")[1];
                            var d = NTP.fixTime() - parseInt(t, 10);
                            if (d < (1000 * 60 * NTP.resyncTime)) {
                                return false;
                            }
                        } catch (e) {
                        }
                    }
                    NTP.getServerTime();
                },
                getNow: function () {
                    var date = new Date();
                    return date.getTime();
                },
                //分析服务器响应
                parseServerResponse: function (data) {
                    var NtpStartTime = storage.get("NtpStartTime");
                    var NtpStopTime = NTP.getNow();
                    var origtime = parseInt(data.data.t);//起始时间
                    var delay = ((NtpStopTime - NtpStartTime) / 2);//延迟
                    var offset = NtpStopTime - origtime - delay;//抵消
                    NTP.serverTimes.push(offset);
                    NTP.serverDelay.push(delay);
            
                    // 因为网络问题，需要多次获取偏移值，获取平均值
                    if (NTP.serverTimes.length >= NTP.requiredResponses) {
                        var sumOffset = 0;
                        var sumDelay = 0;
                        var i = 0;
                        for (i = 0; i < NTP.serverTimes.length; i++) {
                            sumOffset += NTP.serverTimes[i];
                            sumDelay += NTP.serverDelay[i];
                        }
                        var averageOffset = Math.round(sumOffset / i);
                        var averageDelay = Math.round(sumDelay / i);
                        storage.put("NTPClockOffset", averageOffset + '|' + NTP.fixTime()); // 保存获得offset时的时间戳
                        storage.put("NTPClockDelay", averageDelay); // 保存获得offset时的时间戳
                    } else {
                        NTP.getServerTime();
                    }
                },
                //获取服务器时间并判断是否获取成功
                getServerTime: function () {
                    var NtpStartTime = NTP.getNow();
                    storage.put("NtpStartTime", NtpStartTime);
                    var res = http.get(NTP.serverUrl);
                    if (res.statusCode !== 200) {
                        toast("获取网络时间失败: " + res.statusCode + " " + res.statusMessage);
                        return false;
                    } else {
                        NTP.parseServerResponse(res.body.json());
                    }
                },
                //固定时间
                fixTime: function (timeStamp) {
                    if (!timeStamp) {
                        timeStamp = NTP.getNow();
                    }
                    var offset = storage.get("NTPClockOffset");
                    try {
                        if (!offset) {
                            offset = 0;
                        } else {
                            offset = offset.split("|")[0];
                        }
                        if (isNaN(parseInt(offset, 10))) {
                            return timeStamp;
                        }
                        return timeStamp + parseInt(offset, 10);
                    } catch (e) {
                        return timeStamp;
                    }
                }
            };
            
        }catch(e){
            log("异常错误1") //错误处理,这样程序就不会崩溃,而且继续执行.
        
        }
        
       
       
       
           // 获取默认开始时间
           function getTime() {
               var fmt = "YYYY-MM-dd hh:mm:ss";
               var d = new Date();
               var hh = d.getHours();
               var mm = d.getMinutes();
               var ss = d.getSeconds();
               if (mm < 30) {
                mm = 30
                ss = 00
               }
               else{
                hh+=1
                mm = 00
                ss = 00       
               }
               
               var o = {
                   "Y+": d.getYear() + 1900,
                   "M+": d.getMonth() + 1,
                   "d+": d.getDate(),
                   "h+": hh,
                   // "m+": d.getMinutes(),
                   // "s+": d.getSeconds()
                   "m+": mm,
                   "s+": ss
               };
               for (var k in o) {
                   if (new RegExp("(" + k + ")").test(fmt)) {
                       fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 4) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                   }
               }
               fmt = fmt.replace(/-/g, '/');
               return fmt;
             };
       
                //定义初始化界面数据
                var storage = storages.create("拼多多");
                threads.start(NTP.sync);
    
                 //初始化淘宝界面
           setTimeout(initConfig_pdd, 500);
           function initConfig_pdd() {     
            NTPClockOffset = storage.get("NTPClockOffset", "0");
            NTPClockDelay = storage.get("NTPClockDelay", "0");
            if (!NTPClockOffset) {
            NTPClockOffset = 0;
            } else {
            NTPClockOffset = parseInt(NTPClockOffset.split("|")[0]);
            }  
               ui.startTime_pdd.setText(getTime());
               ui.pinlv_pdd.setText(storage.get("pinlv_pdd", "100").toString());
               ui.lastTime_pdd.setText(storage.get("lastTime_pdd", "10").toString());   
               ui.delaytime_pdd.setText(storage.get("delaytime_pdd", "200").toString());  
             }
             
                // 时间戳转时间字符串
                function add0(m) {
                    return m < 10 ? '0' + m : m
                }
                function getNow() {
                    var now = new Date().getTime();
                    return now - NTPClockOffset; 
                }
            
                function formatDate(needTime) {
                    //needTime是整数，否则要parseInt转换
                    var time = new Date(parseInt(needTime));
                    var h = time.getHours();
                    var mm = time.getMinutes();
                    var s = time.getSeconds();
                    var S = time.getMilliseconds();
                    return add0(h) + ':' + add0(mm) + ':' + add0(s)+":"+add0(S);
                }
            
            
                  // 检测时间字符串是否有效
                function strDateTime(str) {
                    var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
                    var r = str.match(reg);
                    if (r == null) return false;
                    var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
                    return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
                }
            
               // 淘宝程序主要逻辑
          ui.ok_pdd.click(function () {
            // 检查无障碍服务
            if (auto.service == null) {
                   toast("请先开启无障碍服务！");
                   return;
               }
               //接收界面数据
                   startTime_pdd = ui.startTime_pdd.getText().toString();
                   pinlv_pdd = parseInt(ui.pinlv_pdd.getText());
                   lastTime_pdd = parseInt(ui.lastTime_pdd.getText());
                   delaytime_pdd = parseInt(ui.delaytime_pdd.getText());
                   if (!strDateTime(startTime_pdd)) {
                       ui.startTime_pdd.setError("日期错误，请重新输入！");
                       return;
                   }
                   //传递界面数据      
                   storage.put("pinlv_pdd", pinlv_pdd);
                   storage.put("lastTime_pdd", lastTime_pdd);
                   storage.put("delaytime_pdd", delaytime_pdd);
           
                   //按下开始运行
                     if(ui.ok_pdd.getText()=="开始运行") {
                       ui.ok_pdd.setText("停止运行");    
                       threads.start(拼多多);
                       device.keepScreenOn()//保持屏幕常亮
                   }else{
                       ui.ok_pdd.setText("开始运行");
                       console.clear();
                       console.hide();
                       threads.shutDownAll();
                       device.cancelKeepingAwake();   
                       }          
           }); 
    function 拼多多(){
        var middle = device.width / 2 -400;      
        console.setPosition(middle, 0);
        console.setGlobalLogConfig({ "file": "/sdcard/shopping日志.txt" });
        console.show();
        var DetailPage =0;
        var notDetailPage = 0;
        var notInDetailPage = 0
    
        logWithTime("欢迎使用shopping拼多多抢卷模式!"); 
        sleep(800); 
        logWithTime("请勿用于非法用途");  
        sleep(800); 
        logWithTime("请打开拼多多，并进入需要抢购商品的详情页！");
        sleep(800); 
        var startTime_pdd1 = new Date(Date.parse(startTime_pdd)).getTime();
        var endTime = new Date(startTime_pdd1.valueOf() + lastTime_pdd * 1000).getTime();
        var shoppingingtime = startTime_pdd1 - delaytime_pdd; 
        
        
        reviewtime();
         //判断实际时间是否大于抢购时间
    function reviewtime(){
        var tt = getNow();
           if (tt > shoppingingtime) {
                console.warn("您的时间已经错过了哦,请重新输入时间！");
                sleep(2000);
                console.clear();
                console.hide();
                threads.shutDownAll();
            }
           if (tt < shoppingingtime){
                logWithTime("您的抢卷时间为：" + formatDate(shoppingingtime));
                logWithTime("距离抢卷时间还剩"+(startTime_pdd1-tt)/1000+"秒"+"请耐心等待");
                }
            }
             // 检测是否在商品详情页
    x = setInterval(function () {
        var t = getNow();
        if (t < shoppingingtime) {
            if (className("android.widget.RelativeLayout").depth(6).drawingOrder(9).exists()) {
                if (DetailPage === 0) {
                    logWithTime("已进入商品详情页，请等待......");
                    DetailPage++;
                    notDetailPage = 0
                }
    
            } else {
                if (notInDetailPage === 0) {
                    logWithTime("未进入商品详情页，请进入，否则进行抢卷！");
                    DetailPage = 0;
                    notInDetailPage++
                }
            }
        } else {
            not_in_Detail_Page = 0;  // 商品详情页状态复位
            clearInterval(x)
        }
    }, 500);
    
    z = setInterval(function () {
        var t = getNow();
        if(t >= shoppingingtime && t < endTime){                
            logWithTime("开始抢卷")
            开始抢卷()
            clearInterval(z);        
        }  
      },10)      
    }
    
    function 开始抢卷()
    {
        var 频率 = ui.pinlv_pdd.text()
        var endTime = lastTime_pdd * 1000;
        
    
        threads.start(function(){
            setInterval(function(){ 
        if(className("android.widget.TextView").text("领取").depth(8).drawingOrder(3).exists())
        {
            className("android.widget.TextView").text("领取").depth(8).drawingOrder(3).click()
        }
        },频率);
        });
    
        threads.start(function(){
            setInterval(function(){ 
                sleep(endTime)
                logWithTime("超出预定抢购时长，抢购结束");
                device.cancelKeepingAwake();
                Panic_buying_end();                  
        },频率)
    }) 
    }
    });
    
    function Panic_buying_end(){    
        device.cancelKeepingAwake()//关闭屏幕常亮
        logWithTime("本次抢购结束");
        threads.shutDownAll()
    }
  
